Skip to content

Instantly share code, notes, and snippets.

@abbodi1406
Created July 28, 2023 13:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abbodi1406/d061bb3ac22a015947414ef988053eef to your computer and use it in GitHub Desktop.
Save abbodi1406/d061bb3ac22a015947414ef988053eef to your computer and use it in GitHub Desktop.
Get updates' UpdateID from Microsoft Update Catalog
Param(
[parameter(Mandatory)][string]$KBnumber,
[string]$arch,
[string]$vers
)
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Enum]::ToObject([Net.SecurityProtocolType], 3072)
$ProgressPreference = 'SilentlyContinue'
$search = Invoke-WebRequest -Uri ("https://www.catalog.update.microsoft.com/Search.aspx?q={0}" -F $KBnumber) -Headers @{"Accept-Language"="en-US;q=0.8,en;q=0.6"}
$document = $search.ParsedHtml
$table = $document.GetElementById('ctl00_catalogBody_updateMatches')
if ($null -ne $table) {
foreach ($row in $table.GetElementsByTagName("TR")) {
$cols = $row.GetElementsByTagName("TD");
if ($null -eq $cols) {continue}
if ($null -eq $cols[2].InnerText) {continue}
$title = $cols[1].InnerText
if ($title -match "Dynamic Cumulative") {continue}
if ($null -ne $vers) {
if ($title -notmatch $vers) {continue}
}
if ($null -ne $arch) {
if ($title -match "x64") {
if ($arch -eq "x86") {continue}
if ($arch -eq "ARM64") {continue}
} elseif ($title -match "ARM64") {
if ($arch -eq "x86") {continue}
if ($arch -eq "x64") {continue}
} else {
if ($arch -eq "x64") {continue}
}
}
($cols[7].GetElementsByTagName("INPUT")[0]).id
}
}
@abbodi1406
Copy link
Author

Examples:

all IDs
.\GetUpdateID.ps1 KB5028245

specific architecture
.\GetUpdateID.ps1 KB5028245 x64

specific version or product
.\GetUpdateID.ps1 5028264 x64 Server
.\GetUpdateID.ps1 5028264 x64 Embedded
.\GetUpdateID.ps1 5028166 x86 22H2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment