Skip to content

Instantly share code, notes, and snippets.

@blakedrumm
Last active February 28, 2024 00:37
Show Gist options
  • Save blakedrumm/6776782852acecbe249fe78558918860 to your computer and use it in GitHub Desktop.
Save blakedrumm/6776782852acecbe249fe78558918860 to your computer and use it in GitHub Desktop.
Automate Microsoft download details extraction effortlessly with this PowerShell script. Retrieve title, version, release date, and URL information using provided IDs.
<#
Author: Blake Drumm (blakedrumm@microsoft.com)
Date Created: February 27th, 2024
Description:
This PowerShell script automates the extraction of key details like title, version, release date, and URL for Microsoft downloads based on provided IDs.
By utilizing web scraping methods, it facilitates the seamless retrieval and organization of essential information from Microsoft's download pages.
#>
$FinalOutput = @()
$x = 0
# Define the IDs you want to process
$ids = "692,786,1451,2268,4419,54509,54524,54525,54526,54587,54588,54653,54701,54791,54806,54918,55025,55030,55033,55763,55792,55990,56033,5618,56203,56204,56557,56558,56559,56560,57171,57172,57173,57381,57382,57511,57594,57776,57958,57990,58208,100782,101203,101312,103379,104858,12962,13302,13819,14720,16159,1653,17998,19395,23251,23964,24164,24233,26795,26934,29269,29270,29304,29696,30003,34765,34766,35590,36438,36496,36775,36784,36817,38198,38829,39039,39062,39617,39709,39978,40797,40798,40800,40801,40802,40803,40807,40809,40858,40867,40876,41539,41560,41672,41696,42066,42522,43707,44279,44576,44991,45525,46371,46924,47364,50013,50379,51189,51479,52043,52764,53895,53900,54057,54058,54064,54081,54113,54271,54291,54300,54303,54445,54554,54653,54791,54918,55025,55030,55033,55763,55792,55990,56033,56203,56204,56557,56558,56559,56560,57171,57172,57173,57381,57382,57511,57594,57776,57958,58208,100782,101203,101312,103379,104858" -split ","
foreach ($id in $ids)
{
$x++
# Define the URL for the current ID
$searchUrl = "https://www.microsoft.com/en-us/download/details.aspx?id=$id"
Write-Verbose -Verbose "Processing ID ($x/$($ids.count)): $id"
# Fetch the content of the page for the current ID
try
{
$pageContent = Invoke-WebRequest -Uri $searchUrl -ErrorAction Stop
}
catch
{
Write-Warning "Unable to process URL: $searchUrl"
continue
}
$rawContent = $pageContent.RawContent -split "`n"
# Search for the lines that contain the required details
$matchedTitle = $rawContent | Select-String -Pattern '"downloadTitle":"([^"]+)"' -AllMatches
$matchedVersion = $rawContent | Select-String -Pattern '"version":"([^"]+)"' -AllMatches
$matchedPublishDate = $rawContent | Select-String -Pattern '"datePublished":"([^"]+)"' -AllMatches
$matchedURLid = $rawContent | Select-String -Pattern '"url":"https://www\.microsoft\.com/.*/download/details\?id=(\d+)"' -AllMatches
# If a match is found, extract it
if ($matchedTitle.Matches.Count -gt 0)
{
$downloadTitle = $matchedTitle.Matches[0].Groups[1].Value
$downloadVersion = $matchedVersion.Matches[0].Groups[1].Value
$downloadPublishDate = $matchedPublishDate.Matches[0].Groups[1].Value
$downloadURLid = $matchedURLid.Matches[0].Groups[1].Value
# Convert the string to a DateTime object
$dateTime = ([datetime]::Parse($downloadPublishDate, [Globalization.CultureInfo]::InvariantCulture, [Globalization.DateTimeStyles]::RoundtripKind))
# Add the details to the final output
$FinalOutput += [PSCustomObject]@{
'Title' = $downloadTitle
'Version' = $downloadVersion
'Release Date' = $dateTime
'URL' = "https://www.microsoft.com/download/details.aspx?id=$downloadURLid"
}
}
else
{
Write-Verbose -Verbose "No matching title found for ID: $id"
}
}
Write-Verbose -Verbose "----------------------------------"
$FinalOutput = $FinalOutput | Select-Object * -Unique | Sort-Object 'Release Date'
# Write to Output
$FinalOutput
# Write to CSV file
$FinalOutput | Export-Csv -NoTypeInformation -Path C:\Users\blakedrumm\Documents\ManagementPack-List.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment