Created
March 6, 2016 15:02
-
-
Save theramiyer/a09444caaa60bb64b48c to your computer and use it in GitHub Desktop.
Script to read the "What's new" page for System Center Endpoint Protection definition. It collects the version number and the time it was released, and updates a predefined CSV file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region Initial variable declaration | |
$Uri = "https://www.microsoft.com/security/portal/definitions/whatsnew.aspx" | |
$ScepVersionInventoryPath = "C:\Users\Ram\Downloads\SCEP Version History.csv" | |
#endregion | |
Clear-Host | |
# Function to convert UTC time to local time. | |
Function Get-LocalTime($UtcTime) | |
{ | |
$TimeZone = [System.TimeZoneInfo]::FindSystemTimeZoneById('Central Standard Time') | |
$LocalTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($UtcTime, $TimeZone) | |
Return $LocalTime | |
} | |
# Function to update the SCEP definition last version to the inventory. | |
Function Update-ScepVersionHistory() | |
{ | |
# Read the web page | |
$Html = Invoke-WebRequest -Uri $Uri | |
$WebPageText = ($Html.ParsedHtml.getElementsByTagName("div") | Where-Object{$_.className -eq "span bp0-col-1-1 bp1-col-1-1 bp2-col-1-1 bp3-col-1-1"}).innerText | |
# Search for the Definition Last Version | |
If(($WebPageText | Out-String) -Match "(?sm)The latest update is:\s+(.*?)\s+Download the latest update") | |
{ | |
$ScepVersion = $Matches[1] | |
} | |
# Search for the release date and time | |
If(($WebPageText | Out-String) -Match "(?sm)Definition available date.{6}\s+(.*?)\sUTC") | |
{ | |
$ReleaseTime = $Matches[1] | |
} | |
# Manipulate the release time | |
$ReleaseTime = $ReleaseTime -replace ",",", " | |
$ReleaseTimeUtc = [DateTime]$ReleaseTime | |
$ReleaseTimeCst = (Get-LocalTime $ReleaseTimeUtc) | |
# Import the information from the existing Version History Inventory into a hash table | |
$Table = Import-Csv -Path $ScepVersionInventoryPath -Header "Version", "ReleaseDate" | Select-Object -Skip 1 | |
$ScepVersionTable = @{} | |
foreach ($Row in $Table) | |
{ | |
Write-Host $Row.Version $Row.ReleaseDate | |
$ScepVersionTable[$Row.Version] = $Row.ReleaseDate | |
} | |
# Check for newer versions and add the current one if it's absent | |
if (! $ScepVersionTable.ContainsKey($ScepVersion)) | |
{ | |
$ScepVersionTable.Add($ScepVersion, $ReleaseTimeCst) | |
$ScepVersionTable.GetEnumerator() | Sort-Object -Property Value -Descending | Select-Object -Property @{Label = 'Version'; Expression = {$_.Name}}, @{Label = 'Release Date (CST)'; Expression = {$_.Value}} | Export-Csv -Path $ScepVersionInventoryPath -NoTypeInformation | |
} | |
} | |
Update-ScepVersionHistory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment