Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#09/03/2021
- EDIT : Adding Extended Support Check (ESU program)
- #>
- [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
- $os_name = (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ProductName')
- $search = $os_name.ToString().Replace(" ",'%20')
- $display = (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DisplayVersion')
- if ($display -eq $null){
- $display = [System.Environment]::OSVersion.Version.Build
- }
- #Works on 2016/W10/W8
- $wrongly_called_api = Invoke-WebRequest -ErrorAction SilentlyContinue -Uri "https://docs.microsoft.com/api/contentbrowser/search/lifecycles?locale=en-us&terms=$search&facet=products&%24top=1" -Headers @{
- "method"="GET"
- "authority"="docs.microsoft.com"
- "scheme"="https"
- "user-agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
- "accept"="*/*"
- "sec-fetch-site"="same-origin"
- "sec-fetch-mode"="cors"
- "sec-fetch-dest"="empty"
- "accept-encoding"="gzip, deflate, br"
- }
- #Workaround for older version of Powershell
- if ($wrongly_called_api -eq $null){
- $wrongly_called_api = Invoke-WebRequest -UseBasicParsing -Uri "https://docs.microsoft.com/api/contentbrowser/search/lifecycles?locale=en-us&terms=$search&facet=products&%24top=1" -Headers @{
- "method"="GET"
- "authority"="docs.microsoft.com"
- "scheme"="https"
- "sec-fetch-site"="same-origin"
- "sec-fetch-mode"="cors"
- "sec-fetch-dest"="empty"
- "accept-encoding"="gzip, deflate, br"
- }
- }
- $json = $wrongly_called_api.Content | ConvertFrom-Json
- $search_result = Invoke-WebRequest ("https://docs.microsoft.com/en-us"+$json.results.Url)
- $dates = ($search_result.Content -split "<tbody>" -split "</tbody>" )[1,3] -split "</tr>"
- $headers = (($search_result.Content -split "<tbody>" -split "</tbody>" )[0] -split "<thead>" -split "</thead>")[1] -split "<tr>" -split "</tr>"
- $headers = (($headers -split '<th align="right">')[2..(($headers -split '<th align="right">').Count)] -replace '</th>').Trim() | Where-Object {$_}
- $sorted_info = @()
- $dates | % {
- $minmax = ($_ -split "<local-time datetime=`"")[1..(($_ -split "<local-time datetime=`"").Count -1)] | % {(($_ -split '</local-time>')[0] -split '">')[1]}
- if($minmax -ne $null){
- $value = [PSCustomObject]@{
- Name = ($_ -split"<td>" -split "</td>")[1]
- Start = [Datetime]$minmax[0]
- End= [Datetime]$minmax[1]
- }
- if ($headers[-1] -like "Extended End Date"){
- $extended = [Datetime]$minmax[2]
- $value | Add-Member -MemberType NoteProperty -Name 'Extended' -Value $extended
- }
- $sorted_info += $value
- }
- }
- if ((get-date) -lt ($sorted_info | where Name -Match $display | select -expand End)){
- Write-Host -ForegroundColor Green "OS currently supported"
- }
- else{
- Write-Host -ForegroundColor Red "OS out of support"
- if ((get-date) -lt ($sorted_info | where Name -Match $display | select -expand Extended)){
- Write-Host -ForegroundColor Yellow "ESU is still supported"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement