Skip to content

Instantly share code, notes, and snippets.

@theramiyer
Created March 6, 2016 15:02
Show Gist options
  • Select an option

  • Save theramiyer/a09444caaa60bb64b48c to your computer and use it in GitHub Desktop.

Select an option

Save theramiyer/a09444caaa60bb64b48c to your computer and use it in GitHub Desktop.

Revisions

  1. Ram Iyer created this gist Mar 6, 2016.
    48 changes: 48 additions & 0 deletions Update-ScepVersionHistoryTable.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    #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