Skip to content

Instantly share code, notes, and snippets.

@StefanScherer
Last active September 26, 2019 21:08
Show Gist options
  • Save StefanScherer/de02a89b4d6ea0e330678c222b4e8270 to your computer and use it in GitHub Desktop.
Save StefanScherer/de02a89b4d6ea0e330678c222b4e8270 to your computer and use it in GitHub Desktop.
Is my Windows Server up to date? Let's check it with latest Windows image tags from MCR :-) 🐳
$ErrorActionPreference = 'Stop'
# fetch the current version number from host
$current=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion")
$currUBR=$current.UBR
# fetch the maximum version number from MCR by filtering and sorting the JSON result
$prefix="$($current.CurrentMajorVersionNumber).$($current.CurrentMinorVersionNumber).$($current.CurrentBuildNumber)."
$json=$(Invoke-WebRequest -UseBasicParsing https://mcr.microsoft.com/v2/windows/servercore/tags/list | ConvertFrom-Json)
$hubUBR=($json.tags | Where-Object -FilterScript { $_.StartsWith($prefix) -and $_ -Match "^\d+\.\d+\.\d+\.\d+$" } |%{[System.Version]$_}|sort)[-1].Revision
Write-Output "Host Update Build Revision $currUBR, Hub Update Build Revision $hubUBR"
if ($currUBR -Lt $hubUBR) {
Write-Error "Your host has update revision $currUBR, but should be updated to $hubUBR!"
} else {
Write-Output "Your host seems up to date."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment