Advertisement
Acquira

OS_EOL_Checker_Bad_API

Sep 2nd, 2021 (edited)
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#09/03/2021
  2.     EDIT : Adding Extended Support Check (ESU program)
  3. #>
  4.  
  5. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  6.  
  7. $os_name =  (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ProductName')
  8. $search = $os_name.ToString().Replace(" ",'%20')
  9.  
  10. $display =  (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DisplayVersion')
  11. if ($display -eq $null){
  12.     $display = [System.Environment]::OSVersion.Version.Build
  13. }
  14.  
  15. #Works on 2016/W10/W8
  16. $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 @{
  17. "method"="GET"
  18.   "authority"="docs.microsoft.com"
  19.   "scheme"="https"
  20.   "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"
  21.   "accept"="*/*"
  22.   "sec-fetch-site"="same-origin"
  23.   "sec-fetch-mode"="cors"
  24.   "sec-fetch-dest"="empty"
  25.   "accept-encoding"="gzip, deflate, br"
  26. }
  27.  
  28. #Workaround for older version of Powershell
  29. if ($wrongly_called_api -eq $null){
  30.     $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 @{
  31.     "method"="GET"
  32.       "authority"="docs.microsoft.com"
  33.       "scheme"="https"
  34.       "sec-fetch-site"="same-origin"
  35.       "sec-fetch-mode"="cors"
  36.       "sec-fetch-dest"="empty"
  37.       "accept-encoding"="gzip, deflate, br"
  38.     }
  39. }
  40.  
  41.  
  42. $json = $wrongly_called_api.Content | ConvertFrom-Json
  43. $search_result = Invoke-WebRequest ("https://docs.microsoft.com/en-us"+$json.results.Url)
  44.  
  45. $dates = ($search_result.Content -split "<tbody>" -split "</tbody>" )[1,3] -split "</tr>"
  46. $headers = (($search_result.Content -split "<tbody>" -split "</tbody>" )[0] -split "<thead>" -split "</thead>")[1] -split "<tr>" -split "</tr>"
  47. $headers = (($headers -split '<th align="right">')[2..(($headers -split '<th align="right">').Count)] -replace '</th>').Trim() | Where-Object {$_}
  48.  
  49. $sorted_info = @()
  50.  
  51. $dates | % {
  52.    
  53.     $minmax = ($_ -split "<local-time datetime=`"")[1..(($_ -split "<local-time datetime=`"").Count -1)] | % {(($_ -split '</local-time>')[0] -split '">')[1]}
  54.     if($minmax -ne $null){
  55.         $value = [PSCustomObject]@{
  56.             Name = ($_ -split"<td>" -split "</td>")[1]
  57.             Start = [Datetime]$minmax[0]
  58.             End= [Datetime]$minmax[1]
  59.         }
  60.         if ($headers[-1] -like "Extended End Date"){
  61.             $extended = [Datetime]$minmax[2]
  62.             $value | Add-Member -MemberType NoteProperty -Name 'Extended' -Value $extended
  63.         }
  64.         $sorted_info += $value
  65.     }
  66. }
  67.  
  68.  
  69.  
  70. if ((get-date) -lt ($sorted_info | where Name -Match $display | select -expand End)){
  71.     Write-Host -ForegroundColor Green "OS currently supported"
  72. }
  73. else{
  74.     Write-Host -ForegroundColor Red "OS out of support"
  75.     if ((get-date) -lt ($sorted_info | where Name -Match $display | select -expand Extended)){
  76.         Write-Host -ForegroundColor Yellow "ESU is still supported"
  77.     }
  78. }
  79.  
  80.  
  81.  
  82.  
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement