Skip to content

Instantly share code, notes, and snippets.

Last active November 20, 2023 04:11
  • Star 33 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save keithga/1ad0abd1f7ba6e2f8aff63d94ab03048 to your computer and use it in GitHub Desktop.
script to get latest build.
Get the latest Cumulative update for Windows
This script will return the list of Cumulative updates for Windows 10 and Windows Server 2016 from the Microsoft Update Catalog.
Copyright Keith Garner (, All rights reserved.
Get the latest Cumulative Update for Windows 10 x64
Windows 10 Build Number used to filter avaible Downloads
10240 - Windows 10 Version 1507
10586 - Windows 10 Version 1511
14393 - Windows 10 Version 1607 and Windows Server 2016
15063 - Windows 10 Version 1703
16299 - WIndows 10 Version 1709
Specify a specific search filter to change the target update behaviour. The default will only Cumulative updates for x86 and x64.
If Mulitple Filters are specified, only string that match *ALL* filters will be selected.
Cumulative - Download Cumulative updates.
Delta - Download Delta updates.
x86 - Download x86
x64 - Download x64
Get the latest Cumulative Update for Windows 10 x86
.\Get-LatestUpdate.ps1 -Filter 'Cumulative','x86'
Get the latest Cumulative Update for Windows Server 2016
.\Get-LatestUpdate.ps1 -Filter 'Cumulative','x64' -Build 14393
Get the latest Cumulative Updates for Windows 10 (both x86 and x64) and download to the %TEMP% directory.
.\Get-LatestUpdate.ps1 | Start-BitsTransfer -Destination $env:Temp
[Parameter(Mandatory=$False, HelpMessage="JSON source for the update KB articles.")]
[string] $StartKB = '',
[Parameter(Mandatory=$False, HelpMessage="Windows build number.")]
[string] $BUild = '16299',
[Parameter(Mandatory=$False, HelpMessage="Windows update Catalog Search Filter.")]
[string[]] $Filter = @( "Cumulative" )
#region Support Routine
Function Select-LatestUpdate {
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]
Begin {
$MaxObject = $null
$MaxValue = [version]::new("0.0")
Process {
ForEach ( $Update in $updates ) {
Select-String -InputObject $Update -AllMatches -Pattern "(\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)" |
ForEach-Object { $_.matches.value } |
ForEach-Object { $_ -as [version] } |
ForEach-Object {
if ( $_ -gt $MaxValue ) { $MaxObject = $Update; $MaxValue = $_ }
End {
$MaxObject | Write-Output
#region Find the KB Article Number
Write-Verbose "Downloading $StartKB to retrieve the list of updates."
$kbID = Invoke-WebRequest -Uri $StartKB |
Select-Object -ExpandProperty Content |
ConvertFrom-Json |
Select-Object -ExpandProperty Links |
Where-Object level -eq 2 |
Where-Object text -match $BUild |
Select-LatestUpdate |
Select-Object -First 1
#region get the download link from Windows Update
Write-Verbose "Found ID: KB$($kbID.articleID)"
$kbObj = Invoke-WebRequest -Uri "$($KBID.articleID)"
$Available_KBIDs = $kbObj.InputFields |
Where-Object { $_.type -eq 'Button' -and $_.Value -eq 'Download' } |
Select-Object -ExpandProperty ID
$Available_KBIDs | out-string | write-verbose
$kbGUIDs = $kbObj.Links |
Where-Object ID -match '_link' |
Where-Object { $_.OuterHTML -match ( "(?=.*" + ( $Filter -join ")(?=.*" ) + ")" ) } |
ForEach-Object { $'_link','') } |
Where-Object { $_ -in $Available_KBIDs }
foreach ( $kbGUID in $kbGUIDs )
Write-Verbose "`t`tDownload $kbGUID"
$Post = @{ size = 0; updateID = $kbGUID; uidInfo = $kbGUID } | ConvertTo-Json -Compress
$PostBody = @{ updateIDs = "[$Post]" }
Invoke-WebRequest -Uri '' -Method Post -Body $postBody |
Select-Object -ExpandProperty Content |
Select-String -AllMatches -Pattern "(http[s]?\://download\.windowsupdate\.com\/[^\'\""]*)" |
Select-Object -Unique |
ForEach-Object { [PSCustomObject] @{ Source = $_.matches.value } } # Output for BITS
Copy link

jm0477 commented Nov 11, 2018

Hi Keith, I found the startKB url is not updating since oct,2018. By using this script, we can only find the latest CU is October,2018. but cannot find anyone new.
I try to find the json format update history but no luck. could you shed some light please?

Copy link

Hey Keith, Much like what jm0477 has mentioned above, I too have come across this script recently and noticed that for build 14393 the latest update the startKB url is showing is 8/2018 or KB KB4343887. The Latest Cumulative Update out today is KB4467684 with a build version of 14393.2639

I've tried locating a new API url but am not sure where you found that url. Would you be able to help me out in any way.

I'm looking into automating our image build process and this script along with one for service stacking updates would be crucial to getting the latest updates to slipstream into the iso.

Copy link

cdie2k commented Jan 27, 2020

automating our image build process

Hello , did you found a way to automating the image/iso updates?


Copy link

cdie2k commented Feb 13, 2020

found part of the solution, with "Install-Module -Name MSCatalog" we will have the option to download the msu. and there are others script to mount the iso and install the msu with dsim (I didnt test it, yet)

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