This repository was archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGenerateBuildNumbers.ps1
More file actions
77 lines (62 loc) · 2.79 KB
/
GenerateBuildNumbers.ps1
File metadata and controls
77 lines (62 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#This function scrapes the TechNet page for Exchange Server build numbers and release
#dates to match the build numbers for Exchange Servers in the organization.
##Reference: Lee Holmes article on extracting tables from web pages was very useful for developing this
#Link: #http://www.leeholmes.com/blog/2015/01/05/extracting-tables-from-powershells-invoke-webrequest/
Function Get-ExchangeBuildNumbers()
{
[CmdletBinding()]
param ()
Write-Verbose "Fetching Exchange build numbers from TechNet"
$URL = "https://docs.microsoft.com/en-us/Exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019"
try
{
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$WebPage = Invoke-WebRequest -Uri $URL -UseBasicParsing -ErrorAction STOP
$WebPage.Content | Out-File BuildNumbers.html
$HTML = New-Object -ComObject "HTMLFile"
$HTML.IHTMLDocument2_write($(Get-Content .\BuildNumbers.html -raw))
$tables = @($HTML.getElementsByTagName("TABLE"))
Write-Verbose "Parsing results from web request"
foreach ($table in $tables)
{
$rows = @($table.Rows)
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 | ForEach-Object { ("" + $_.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) | ForEach-Object { "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
}
}
}
catch
{
Write-Warning $_.Exception.Message
$ExchangeBuildNumbers = "An error occurred. $($_.Exception.Message)"
}
return $ExchangeBuildNumbers
}
$myDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$BuildNumbers = Get-ExchangeBuildNumbers
$BuildNumbers
$BuildNumbers | Export-Clixml $myDir\ExchangeBuildNumbers.xml