Skip to content

Instantly share code, notes, and snippets.

@gwblok
Created December 26, 2019 19:16
Show Gist options
  • Save gwblok/6665fe4b571952aeee3d57a94482a56f to your computer and use it in GitHub Desktop.
Save gwblok/6665fe4b571952aeee3d57a94482a56f to your computer and use it in GitHub Desktop.
Pulls Windows 10 Release Information from Microsoft Website - Scrap HTML
<#
@gwblok (GARYTOWN.COM) 2019.12.26
Used to Grab Windows 10 Release Info and pull into PowerShell
Pulling Tables in was stolen from: https://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/
#>
$URL = "https://winreleaseinfoprod.blob.core.windows.net/winreleaseinfoprod/en-US.html"
[Microsoft.PowerShell.Commands.HtmlWebResponseObject]$WinReleaseWeb = Invoke-WebRequest -Uri $URL
## Extract the tables out of the web request
$tables = @($WinReleaseWeb.ParsedHtml.getElementsByTagName("TABLE"))
$table = $tables[0] #Table 0 = the Basic Table at top of Page with Release Numbers & Support Dates... change this number to get data from other tables
$titles = @()
$rows = @($table.Rows)
$TableData = $null
[System.Collections.ArrayList]$TableData = New-Object -TypeName psobject
## Go through all of the rows in the table
foreach($row in $rows)
{
$cells = @($row.Cells)
## If we've found a table header, remember its titles
if($cells[0].tagName -eq "TH")
{
$titles = @($cells | % { ("" + $_.InnerText).Trim() })
continue
}
## If we haven't found any table headers, make up names "P1", "P2", etc.
if(-not $titles)
{
$titles = @(1..($cells.Count + 2) | % { "P$_" })
}
## Now go through the cells in the the row. For each, try to find the
## title that represents that column and create a hashtable mapping those
## titles to content
$resultObject = [Ordered] @{}
for($counter = 0; $counter -lt $cells.Count; $counter++)
{
$title = $titles[$counter]
if(-not $title) { continue }
$resultObject[$title] = ("" + $cells[$counter].InnerText).Trim()
}
## And finally cast that hashtable to a PSCustomObject
[PSCustomObject] $resultObject
$TableData.Add($resultObject)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment