Last active
September 7, 2026 22:06
-
-
Save mickert/44ad7430624150d432eba1533db72c58 to your computer and use it in GitHub Desktop.
Windows Build & Update Compliance Checker. Reports last Windows Update results and verifies Windows servicing build compliance. (c) 2026 Michel Sijmons - https://mickert.dev - License: Apache 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ===================================================================== | |
| # Windows Build & Update Compliance Checker - v0.22 | |
| # Get-WindowsBuildCompliance.ps1 | |
| # | |
| # Reports last Windows Update results and checks servicing build | |
| # compliance using local WU history and Microsoft Docs servicing | |
| # history tables. | |
| # | |
| # Features: | |
| # - Retrieves latest servicing builds from Microsoft Docs | |
| # - Compares local build against baseline and hotpatch builds | |
| # - Detects silent update failures and missing baseline LCUs | |
| # - Reports last Security, Non-Defender, and general WU results | |
| # - Provides clear admin-friendly output and fallback behavior | |
| # | |
| # Tested on Windows Server 2019/2022/2025 and Windows 11 | |
| # | |
| # Licensed under Apache License 2.0 | |
| # Copyright (c) 2026 Michel Sijmons - https://mickert.dev | |
| # Canonical URL: https://gists.mickert.dev/44ad7430624150d432eba1533db72c58#file-get-windowsbuildcompliance-ps1 | |
| # | |
| # ===================================================================== | |
| # CHANGELOG | |
| # ===================================================================== | |
| # v0.22 (2026-09-08) | |
| # - Added full UBR integrity verification (Registry UBR vs CBS RollupFix vs File High-Water Mark) | |
| # - Added detection of silent failures and registry tampering via multi-source UBR mismatch logic | |
| # - Improved Windows Update Security matcher (exclude .NET + Defender; added Server OS title matching) | |
| # - Refactored Get-WULastUpdates to use configurable regex patterns from Settings block | |
| # - Added SmartStatus output for Last Security/Non-Defender/Last Update blocks | |
| # - Improved admin-friendly output formatting and consistency across all blocks | |
| # - Minor cleanup, readability improvements and comment corrections | |
| # | |
| # v0.21 (2026-09-07) | |
| # - Added future-proof Windows servicing update detection (KB + build + Windows-title matching) | |
| # - Added configurable regex patterns for WU Security update detection | |
| # - Improved WU title matching to correctly detect SSUs, LTSC updates and Windows Server updates | |
| # - Filtered out ISO/GA baseline entries (no KB, no update type) | |
| # - Cleaned up AvailableUpdates/OlderAvailableUpdates formatting (always show KB) | |
| # - Fixed copy/paste issue in Get-WULastUpdates regex block | |
| # - Minor consistency and readability improvements | |
| # | |
| # v0.20 (2026-09-06) | |
| # - Added servicing history fallback when Microsoft Docs is unreachable | |
| # - Improved error handling for Invoke-WebRequest | |
| # - Added admin-friendly fallback output in compliance block | |
| # - Minor regex and parsing optimizations | |
| # | |
| # v0.19 (2026-09-05) | |
| # - Added baseline LCU detection logic | |
| # - Improved build grouping and deduplication | |
| # | |
| # v0.18 (2026-09-04) | |
| # - Added hotpatch classification and priority mapping | |
| # - Initial servicing history parser implemented | |
| # | |
| # ===================================================================== | |
| # DISCLAIMER & LICENSE | |
| # ===================================================================== | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at: | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| # | |
| # DISCLAIMER: | |
| # This script is provided "as-is" without any warranties or guarantees. | |
| # Use at your own risk. The author assumes no liability for any damages, | |
| # data loss, misconfiguration, or operational impact resulting from the | |
| # use of this script. Always test in a controlled environment before | |
| # deploying to production. | |
| # | |
| # ===================================================================== | |
| # COPYRIGHT | |
| # ===================================================================== | |
| # Copyright (c) 2026 Michel Sijmons - https://mickert.dev | |
| # All rights reserved. | |
| # ===================================================================== | |
| Write-Host "*** Windows Build & Update Compliance Checker v0.22 ***" -ForegroundColor Cyan | |
| Write-Host "* (C) 2026 - Michel Sijmons, https://mickert.dev" -ForegroundColor Cyan | |
| Write-Host "* Licensed under Apache License 2.0" -ForegroundColor Cyan | |
| # ===================================================================== | |
| # Settings | |
| # ===================================================================== | |
| # --- regex patterns to match Windows Security updates, you may have to adapt these --- | |
| # Exclude .Net and Defender updates | |
| $patternWuSecUpdateExclude = "(?:Defender|\.NET)\b" | |
| # Windows servicing updates always contain a KB + build number | |
| $patternWuSecUpdateAnd1 = "\(KB\d{6,8}\)" | |
| $patternWuSecUpdateAnd2 = "\(\d{5,}\.\d+\)" | |
| # Some Windows servicing updates use "for Microsoft Windows", "for Windows" or "for Microsoft server operating system" | |
| $patternWuSecUpdateOr = "for\s+(?:Microsoft\s+)?(?:Windows|server operating system)" | |
| # these are used in function Get-WULastUpdates as followed | |
| # $t -notmatch $patternWuSecUpdateExclude -and | |
| # ( | |
| # ($t -match $patternWuSecUpdateAnd1 -and $t -match $patternWuSecUpdateAnd2) -or | |
| # ($t -match $patternWuSecUpdateOr) | |
| # ) | |
| # --- target files to get version from for UBR integrity verification --- | |
| $TargetFilesForUBRVerification = @( | |
| "$env:windir\system32\ntdll.dll", | |
| "$env:windir\system32\kernel32.dll", | |
| "$env:windir\system32\ntoskrnl.exe", | |
| "$env:windir\system32\drivers\cng.sys" | |
| ) | |
| # ===================================================================== | |
| # Maps | |
| # ===================================================================== | |
| $updateMap = @{ | |
| "A" = @{ | |
| Classification = "Early Servicing" | |
| Priority = 1 | |
| } | |
| "B" = @{ | |
| Classification = "Monthly Security" | |
| Priority = 1 | |
| } | |
| "LCU" = @{ | |
| Classification = "Monthly Security" | |
| Priority = 1 | |
| } | |
| "HP" = @{ | |
| Classification = "Hotpatch" | |
| Priority = 2 | |
| } | |
| "HP-CRITICAL" = @{ | |
| Classification = "Hotpatch CRITICAL" | |
| Priority = 2 | |
| } | |
| "HP-FAST" = @{ | |
| Classification = "Hotpatch FAST" | |
| Priority = 2 | |
| } | |
| "HP-SECURITY" = @{ | |
| Classification = "Hotpatch SECURITY" | |
| Priority = 2 | |
| } | |
| "HP-URGENT" = @{ | |
| Classification = "Hotpatch URGENT" | |
| Priority = 2 | |
| } | |
| "OOB" = @{ | |
| Classification = "Out of Band" | |
| Priority = 3 | |
| } | |
| "OOB-SECURITY" = @{ | |
| Classification = "Out of Band SECURITY" | |
| Priority = 3 | |
| } | |
| "OOB-CRITICAL" = @{ | |
| Classification = "Out of Band CRITICAL" | |
| Priority = 3 | |
| } | |
| "OOB-URGENT" = @{ | |
| Classification = "Out of Band URGENT" | |
| Priority = 3 | |
| } | |
| "C" = @{ | |
| Classification = "Preview" | |
| Priority = 4 | |
| } | |
| "D" = @{ | |
| Classification = "Preview" | |
| Priority = 4 | |
| } | |
| "E" = @{ | |
| Classification = "Preview" | |
| Priority = 4 | |
| } | |
| "F" = @{ | |
| Classification = "Preview" | |
| Priority = 4 | |
| } | |
| "LCU-PREVIEW" = @{ | |
| Classification = "Preview" | |
| Priority = 4 | |
| } | |
| } | |
| $baselineTypes = @('B','LCU') | |
| function Get-UpdateInfo { | |
| [CmdletBinding()] | |
| param([string]$updateType) | |
| if (-not $updateType -or -not ($updateType -match '\b([A-Z][A-Z\-]*)\b')) { | |
| return [PSCustomObject]@{ | |
| Code = $null | |
| Classification = "Unknown" | |
| Priority = 999 | |
| } | |
| } | |
| $code = $Matches[1].ToUpper() | |
| $info = $updateMap[$code] | |
| if ($null -eq $info) { | |
| return [PSCustomObject]@{ | |
| Code = $code | |
| Classification = "Unknown" | |
| Priority = 999 | |
| } | |
| } | |
| return [PSCustomObject]@{ | |
| Code = $code | |
| Classification = $info.Classification | |
| Priority = $info.Priority | |
| } | |
| } | |
| function Get-ServicingHistoryRows { | |
| [CmdletBinding()] | |
| param([string]$Url) | |
| # --- Web request with safe error handling --- | |
| try { | |
| $html = (Invoke-WebRequest -Uri $Url -UseBasicParsing -ErrorAction Stop).Content | |
| } | |
| catch { | |
| Write-Warning "Could not retrieve servicing history from $Url" | |
| return @() # Return empty list so the rest of the script continues safely | |
| } | |
| # Regexes (precompiled) | |
| $tableRegex = [regex]::new( | |
| '(?is)<table[^>]*>(?:(?!</table>).)*?<th[^>]*>\s*Update type\s*</th>(?:(?!</table>).)*?<th[^>]*>\s*Build\s*</th>(?:(?!</table>).)*?</table>', | |
| [System.Text.RegularExpressions.RegexOptions]::Compiled | |
| ) | |
| $thRegex = [regex]::new('<th[^>]*>(.*?)</th>', [System.Text.RegularExpressions.RegexOptions]::Compiled) | |
| $rowRegex = [regex]::new('(?s)<tr[^>]*>(.*?)</tr>', [System.Text.RegularExpressions.RegexOptions]::Compiled) | |
| $tdRegex = [regex]::new('(?s)<td[^>]*>(.*?)</td>', [System.Text.RegularExpressions.RegexOptions]::Compiled) | |
| $rows = New-Object System.Collections.Generic.List[object] | |
| foreach ($tableMatch in $tableRegex.Matches($html)) { | |
| $tableHtml = $tableMatch.Value | |
| # Extract headers | |
| $headers = New-Object System.Collections.Generic.List[string] | |
| foreach ($h in $thRegex.Matches($tableHtml)) { | |
| $name = $h.Groups[1].Value | |
| $name = $name -replace '<[^>]+>', '' | |
| $name = $name.Trim() -replace '\s+', '' | |
| $headers.Add($name) | |
| } | |
| # Extract rows | |
| foreach ($rowMatch in $rowRegex.Matches($tableHtml)) { | |
| $tds = $tdRegex.Matches($rowMatch.Groups[1].Value) | |
| if ($tds.Count -ne $headers.Count) { continue } | |
| $obj = [ordered]@{} | |
| for ($i = 0; $i -lt $headers.Count; $i++) { | |
| $value = $tds[$i].Groups[1].Value | |
| $value = $value -replace '<[^>]+>', '' | |
| $value = $value.Trim() -replace '\s+', ' ' | |
| $obj[$headers[$i]] = $value | |
| } | |
| $rows.Add([PSCustomObject]$obj) | |
| } | |
| } | |
| return $rows | |
| } | |
| function Get-LatestBuildFromServicingHistory { | |
| [CmdletBinding()] | |
| param() | |
| $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | |
| $major = [int]$cv.CurrentBuild | |
| $localBuild = "$($cv.CurrentBuild).$($cv.UBR)" | |
| $osName = | |
| if ($cv.ProductName -match 'Server') { $cv.ProductName } | |
| elseif ($cv.CurrentBuild -ge 22000) { 'Windows 11' } | |
| else { 'Windows 10' } | |
| $url = | |
| if ($cv.ProductName -match 'Server') { | |
| 'https://learn.microsoft.com/en-us/windows/release-health/windows-server-release-info' | |
| } | |
| elseif ($cv.CurrentBuild -ge 22000) { | |
| 'https://learn.microsoft.com/en-us/windows/release-health/windows11-release-information' | |
| } | |
| else { | |
| 'https://learn.microsoft.com/en-us/windows/release-health/release-information' | |
| } | |
| $rows = | |
| Get-ServicingHistoryRows $url | | |
| ForEach-Object { | |
| # Split build number | |
| $maj = $null | |
| $min = $null | |
| if ($_.Build -match '^\d+\.\d+') { | |
| $maj, $min = $_.Build -split '\.' | |
| } | |
| # Filter on major build (skip early) | |
| if ($maj -ne $major) { return } | |
| # Filter out base/ISO releases (no type, no KB, no update code) | |
| if ( | |
| [string]::IsNullOrWhiteSpace($_.Updatetype) -or | |
| [string]::IsNullOrWhiteSpace($_.KBarticle) | |
| ) { return } | |
| # Enrich rows with metadata | |
| $updateInfo = Get-UpdateInfo $_.Updatetype | |
| # AdditionalUpdateInfo: Type > Classification | |
| $additional = if ($_.Type) { $_.Type } else { $updateInfo.Classification } | |
| # Build enriched object | |
| [PSCustomObject]@{ | |
| Updatetype = $_.Updatetype | |
| Type = $_.Type | |
| Build = $_.Build | |
| KBarticle = $_.KBarticle | |
| Availabilitydate = $_.Availabilitydate | |
| MajorBuild = [int]$maj | |
| MinorBuild = [int]$min | |
| UpdateCode = $updateInfo.Code | |
| Priority = $updateInfo.Priority | |
| AdditionalUpdateInfo = $additional | |
| } | |
| } | | |
| # Deduplicate builds: baseline always wins | |
| Group-Object Build | | |
| ForEach-Object { | |
| $group = $_.Group | |
| $baseline = $group | Where-Object { $_.UpdateCode -in $baselineTypes } | |
| if ($baseline) { | |
| $baseline | Select-Object -First 1 | |
| } | |
| else { | |
| $group | Sort-Object Priority, @{Expression='MinorBuild';Descending=$true} | Select-Object -First 1 | |
| } | |
| } | |
| if (-not $rows -or $rows.Count -eq 0) { | |
| return $null | |
| } | |
| # Latest build per update type | |
| $latestPerType = | |
| $rows | | |
| Group-Object UpdateCode | | |
| ForEach-Object { | |
| $_.Group | | |
| Sort-Object Priority, @{Expression='MinorBuild';Descending=$true} | | |
| Select-Object -First 1 | |
| } | |
| # Match: Does local build match one of the latest builds per type? | |
| $match = $latestPerType | Where-Object { $_.Build -eq $localBuild } | |
| # Determine newest baseline (B/LCU) | |
| $latestBaseline = $latestPerType | | |
| Where-Object { $_.UpdateCode -in $baselineTypes } | | |
| Sort-Object MinorBuild -Descending | | |
| Select-Object -First 1 | |
| # Available updates (newer builds) with priority sorting | |
| $availableUpdates = @( | |
| $latestPerType | | |
| Where-Object { | |
| ([version]$_.Build -gt [version]$localBuild) -and | |
| ([version]$_.Build -ge [version]$latestBaseline.Build) | |
| } | | |
| Sort-Object Priority, @{Expression='MinorBuild';Descending=$true} | |
| ) | |
| # Older updates (for context only) | |
| $olderUpdates = @( | |
| $latestPerType | | |
| Where-Object { | |
| ([version]$_.Build -lt [version]$latestBaseline.Build) | |
| } | | |
| Sort-Object Priority, @{Expression='MinorBuild';Descending=$true} | |
| ) | |
| if ($match) { | |
| if ($match.UpdateCode -notin $baselineTypes) { | |
| $latestBaseline = $latestPerType | | |
| Where-Object { $_.UpdateCode -in $baselineTypes } | | |
| Sort-Object MinorBuild -Descending | | |
| Select-Object -First 1 | |
| if ($latestBaseline -and ([version]$latestBaseline.Build -gt [version]$localBuild)) { | |
| $status = "Behind (baseline update available)" | |
| $latest = $latestBaseline | |
| } | |
| else { | |
| $status = "Up-To-Date" | |
| $latest = $match | |
| } | |
| } | |
| else { | |
| $status = "Up-To-Date" | |
| $latest = $match | |
| } | |
| } | |
| else { | |
| # No match at all ? definitely behind | |
| $status = "Behind (silent failure possible)" | |
| $latest = $latestPerType | Sort-Object MinorBuild -Descending | Select-Object -First 1 | |
| } | |
| [PSCustomObject]@{ | |
| OS = $osName | |
| LocalBuild = $localBuild | |
| LatestBuild = $latest.Build | |
| UpdateType = $latest.Updatetype | |
| AdditionalUpdateInfo = $latest.AdditionalUpdateInfo | |
| KB = $latest.KBarticle | |
| Status = $status | |
| AvailableUpdates = $availableUpdates | |
| OlderUpdates = $olderUpdates | |
| } | |
| } | |
| # ===================================================================== | |
| # Integrity Verification | |
| # ===================================================================== | |
| function Get-OSFileUBRHighWaterMark { | |
| [CmdletBinding()] | |
| param() | |
| if (-not $TargetFilesForUBRVerification) { return 0 } | |
| $HighestUBR = 0 | |
| foreach ($File in $TargetFilesForUBRVerification) { | |
| if (Test-Path $File) { | |
| # Extract the UBR component safely using named regex captures | |
| if ((Get-Item $File).VersionInfo.FileVersion -match '^\d+\.\d+\.\d+\.(?<ubr>\d+)') { | |
| $Version = [int]$Matches['ubr'] | |
| if ($Version -gt $HighestUBR) { $HighestUBR = $Version } | |
| } | |
| } | |
| } | |
| return $HighestUBR | |
| } | |
| function Get-CbsInstalledUBR { | |
| [CmdletBinding()] | |
| param() | |
| $CbsPath = "Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages" | |
| $ValidStates = @(112, 128) # 112 = Installed, 128 = Staged (Pending Reboot) | |
| $RollupKeys = Get-ChildItem -Path $CbsPath -ErrorAction SilentlyContinue | | |
| Where-Object { $_.PSChildName -like "Package_for_RollupFix~31bf3856ad364e35*" } | |
| if (-not $RollupKeys) { return $null } | |
| $ParsedPackages = foreach ($Key in $RollupKeys) { | |
| if ($Key.PSChildName -match '~(?<build>\d+)\.(?<ubr>\d+)\.(?<rev>\d+)\.(?<minor>\d+)') { | |
| $CurrentState = Get-ItemProperty -Path $Key.PSPath -Name "CurrentState" -ErrorAction SilentlyContinue | |
| if ($CurrentState -and $CurrentState.CurrentState -in $ValidStates) { | |
| [PSCustomObject]@{ | |
| Build = [int]$Matches['build'] | |
| UBR = [int]$Matches['ubr'] | |
| Rev = [int]$Matches['rev'] | |
| } | |
| } | |
| } | |
| } | |
| $TrueActivePackage = $ParsedPackages | | |
| Sort-Object Build, UBR, Rev -Descending | | |
| Select-Object -First 1 | |
| if ($TrueActivePackage) { return $TrueActivePackage.UBR } | |
| else { return $null } | |
| } | |
| function Test-BuildCompliance { | |
| [CmdletBinding()] | |
| param() | |
| $info = Get-LatestBuildFromServicingHistory | |
| if (-not $info) { | |
| return $null | |
| } | |
| $localBuild = [version]$info.LocalBuild | |
| $latestBuild = [version]$info.LatestBuild | |
| $status = | |
| if ($localBuild -eq $latestBuild) { "$($info.Status)" } | |
| elseif ($localBuild -lt $latestBuild) { "Behind (silent failure possible) !!!" } | |
| else { "Ahead (Preview/Insider?)" } | |
| # Available updates as CSV | |
| $availableUpdatesList = if ($info.AvailableUpdates.Count -gt 0) { | |
| ($info.AvailableUpdates | ForEach-Object { | |
| "$($_.Updatetype) ($($_.Build)) $($_.KBarticle) [$($_.AdditionalUpdateInfo)]" | |
| }) -join '; ' | |
| } else { | |
| "none" | |
| } | |
| # Available updates as CSV | |
| $olderUpdatesList = if ($info.OlderUpdates.Count -gt 0) { | |
| ($info.OlderUpdates | ForEach-Object { | |
| "$($_.Updatetype) ($($_.Build)) $($_.KBarticle) [$($_.AdditionalUpdateInfo)]" | |
| }) -join '; ' | |
| } else { | |
| "none" | |
| } | |
| [PSCustomObject]@{ | |
| OS = $info.OS | |
| LocalBuild = $info.LocalBuild | |
| LatestBuild = $info.LatestBuild | |
| UpdateType = "$($info.UpdateType) [$($info.AdditionalUpdateInfo)]" | |
| KB = $info.KB | |
| Status = $status | |
| AvailableUpdates = $availableUpdatesList | |
| OlderUpdates = $olderUpdatesList | |
| } | |
| } | |
| #======================================================================== | |
| # WindowsUpdate Check | |
| #======================================================================== | |
| # Helper function to safely expand COM properties | |
| function Expand { | |
| [CmdletBinding()] | |
| param($item, $prop) | |
| try { | |
| return $item.$prop | |
| } | |
| catch { | |
| return $null | |
| } | |
| } | |
| # Helper function to Extract properties | |
| function ExtractProps { | |
| [CmdletBinding()] | |
| param($item) | |
| return [PSCustomObject]@{ | |
| ResultCode = Expand $item "ResultCode" | |
| HResult = Expand $item "HResult" | |
| Title = Expand $item "Title" | |
| Date = Expand $item "Date" | |
| } | |
| } | |
| function Get-WUHistory { | |
| [CmdletBinding()] | |
| param() | |
| $wuSearcher = (New-Object -ComObject Microsoft.Update.Session).CreateUpdateSearcher() | |
| $historyCount = $wuSearcher.GetTotalHistoryCount() | |
| $max = [Math]::Min($historyCount, 1000) | |
| return $wuSearcher.QueryHistory(0, $max) | |
| } | |
| function Get-WULastUpdates { | |
| param($history) | |
| $last = $history | Select-Object -First 1 | |
| $lastNonDef = $null | |
| $lastSec = $null | |
| foreach ($h in $history) { | |
| $t = Expand $h "Title" | |
| if (-not $lastNonDef -and $t -notmatch "Defender") { | |
| $lastNonDef = $h | |
| } | |
| if (-not $lastSec -and ( | |
| $t -notmatch $patternWuSecUpdateExclude -and | |
| ( | |
| ($t -match $patternWuSecUpdateAnd1 -and $t -match $patternWuSecUpdateAnd2) -or | |
| ($t -match $patternWuSecUpdateOr) | |
| ) | |
| )) { | |
| $lastSec = $h | |
| } | |
| if ($lastNonDef -and $lastSec) { break } | |
| } | |
| return [PSCustomObject]@{ | |
| Last = ExtractProps $last | |
| LastNonDef = ExtractProps $lastNonDef | |
| LastSec = ExtractProps $lastSec | |
| } | |
| } | |
| # --- ResultCode mapping --- | |
| $wuMap = @{ | |
| 0 = "Not Started" | |
| 1 = "In Progress" | |
| 2 = "Succeeded" | |
| 3 = "Succeeded With Errors" | |
| 4 = "Failed" | |
| 5 = "Aborted" | |
| } | |
| # --- HResult reason mapping --- | |
| $reasonMap = @{ | |
| 0x00000000 = "Success" | |
| 0x80240017 = "Not Applicable (already installed or not needed)" | |
| 0x8024001E = "Operation Cancelled" | |
| 0x8024001F = "Operation Failed" | |
| 0x80240022 = "WU Server Unavailable" | |
| 0x8024002E = "Update Not Found" | |
| 0x80240030 = "Reboot Required" | |
| 0x80240054 = "Download Failed" | |
| 0x8024005B = "Installation Failed" | |
| } | |
| function MapResult { | |
| [CmdletBinding()] | |
| param($code) | |
| if ($null -eq $code) { return "<no result>" } | |
| $val = $wuMap[$code] | |
| if ($null -eq $val) { return "Unknown" } | |
| return $val | |
| } | |
| function MapReason { | |
| [CmdletBinding()] | |
| param($hresult) | |
| if ($null -eq $hresult) { return "<no hresult>" } | |
| $val = $reasonMap[$hresult] | |
| if ($null -eq $val) { return "Unknown" } | |
| return $val | |
| } | |
| # --- Make some sense of the status codes --- | |
| function SmartStatus { | |
| [CmdletBinding()] | |
| param($props) | |
| $hr = $props.HResult | |
| switch ($hr) { | |
| 0x80240030 { return "RebootRequired" } | |
| 0x8024001E { return "Cancelled" } | |
| 0x80240017 { return "NotApplicable" } | |
| } | |
| $rc = $props.ResultCode | |
| # Aborted | |
| if ($rc -eq 5) { return "Aborted" } | |
| # Genuine failure (ResultCode 4 or HResult failure) | |
| if ($rc -eq 4 -or ($hr -ne 0)) { | |
| return "Failed" | |
| } | |
| # Everything else is healthy | |
| return "Healthy" | |
| } | |
| # --- Output functions --- | |
| function WriteWUDetailBlock { | |
| [CmdletBinding()] | |
| param($name, $props) | |
| $rcText = MapResult $props.ResultCode | |
| $reason = MapReason $props.HResult | |
| $status = SmartStatus $props | |
| Write-Host "== $name ==" | |
| if ($status -ne "Healthy") { | |
| Write-Host "SmartStatus: $status" | |
| } | |
| Write-Host "ResultCode: $($props.ResultCode) ($rcText)" | |
| Write-Host ("HResult: 0x{0:X} ($reason)" -f $props.HResult) | |
| Write-Host "Reason: $reason" | |
| Write-Host "Title: $($props.Title)" | |
| Write-Host "Date: $($props.Date)" | |
| Write-Host "" | |
| } | |
| function WriteWindowsUpdateBlock { | |
| [CmdletBinding()] | |
| param() | |
| Write-Host "=== Last WindowsUpdate Results ===" | |
| $lastUpdates = Get-WULastUpdates (Get-WUHistory) | |
| WriteWUDetailBlock "Last Security Update" $lastUpdates.LastSec | |
| WriteWUDetailBlock "Last Non-Defender Update" $lastUpdates.LastNonDef | |
| WriteWUDetailBlock "Last Update" $lastUpdates.Last | |
| } | |
| function WriteUBRIntegrityVerificationBlock { | |
| [CmdletBinding()] | |
| param() | |
| # --- check registry UBR againts CBS logs and core system files --- | |
| $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | |
| $RegistryUBR = [int]$cv.UBR | |
| $CbsUBR = Get-CbsInstalledUBR | |
| $FileUBR = Get-OSFileUBRHighWaterMark | |
| # Format strings for output | |
| $CbsDisplay = if ($null -eq $CbsUBR) { "None (Base ISO/ResetBase Slipstream)" } else { $CbsUBR } | |
| $FileDisplay = if ($FileUBR -eq 0) { "Unknown" } else { $FileUBR } | |
| # Determine if a warning is necessary | |
| $IntegrityStatus = "Verified (UBR matches RollupFix install in CBS.log and core system files highwatermark)" | |
| if ($CbsUBR -and $RegistryUBR -ne $CbsUBR) { | |
| $IntegrityStatus = "MISMATCH RegistryUBR vs CbsUBR / ALERT (Possible Silent Failure or Registry Tampering)" | |
| } elseif ($FileUBR -gt 0 -and $RegistryUBR -ne $FileUBR) { | |
| $IntegrityStatus = "MISMATCH RegistryUBR vs FileUBR / ALERT (Possible Silent Failure or Registry Tampering)" | |
| } elseif ($CbsUBR -and $FileUBR -gt 0 -and $CbsUBR -ne $FileUBR) { | |
| $IntegrityStatus = "MISMATCH CbsUBR vs FileUBR / ALERT (Possible Silent Failure or Registry Tampering)" | |
| } | |
| Write-Host "=== UBR Integrity Verification ===" | |
| Write-Host "Registry Base UBR: $RegistryUBR" | |
| Write-Host "Component Store UBR: $CbsDisplay" | |
| Write-Host "File High-Water Mark UBR: $FileDisplay" | |
| Write-Host "Subsystem Integrity: $IntegrityStatus" | |
| Write-Host "" | |
| } | |
| function WriteBuildComplianceBlock { | |
| [CmdletBinding()] | |
| param() | |
| Write-Host "=== Build Compliance ===" | |
| $compliance = Test-BuildCompliance | |
| if (-not $compliance) { | |
| Write-Host "Only local build information is shown below (no remote comparison possible)." | |
| Write-Host "" | |
| $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' | |
| $localBuild = "$($cv.CurrentBuild).$($cv.UBR)" | |
| $osName = | |
| if ($cv.ProductName -match 'Server') { $cv.ProductName } | |
| elseif ($cv.CurrentBuild -ge 22000) { 'Windows 11' } | |
| else { 'Windows 10' } | |
| Write-Host "OS: $osName" | |
| Write-Host "LocalBuild: $localBuild" | |
| Write-Host "LatestBuild: <unknown>" | |
| Write-Host "UpdateType: <unknown>" | |
| Write-Host "KB: <unknown>" | |
| Write-Host "Status: Unable to determine (servicing history unavailable)" | |
| Write-Host "AvailableUpdates: <unknown>" | |
| Write-Host "" | |
| return | |
| } | |
| # Normal path | |
| Write-Host "OS: $($compliance.OS)" | |
| Write-Host "LocalBuild: $($compliance.LocalBuild)" | |
| Write-Host "LatestBuild: $($compliance.LatestBuild)" | |
| Write-Host "UpdateType: $($compliance.UpdateType)" | |
| Write-Host "KB: $($compliance.KB)" | |
| Write-Host "Status: $($compliance.Status)" | |
| Write-Host "AvailableUpdates: $($compliance.AvailableUpdates)" | |
| if ($compliance.OlderUpdates -ne "none") { | |
| Write-Host "OlderAvailableUpdates: $($compliance.OlderUpdates)" | |
| } | |
| Write-Host "" | |
| } | |
| #======================================================================== | |
| # Main | |
| #======================================================================== | |
| function main { | |
| [CmdletBinding()] | |
| param() | |
| WriteBuildComplianceBlock | |
| WriteUBRIntegrityVerificationBlock | |
| WriteWindowsUpdateBlock | |
| } | |
| main | |
| # Copyright (c) 2026 Michel Sijmons - https://mickert.dev | |
| # All rights reserved. | |
| # Licensed under Apache License 2.0 | |
| # Latest version: https://gists.mickert.dev/44ad7430624150d432eba1533db72c58#file-get-windowsbuildcompliance-ps1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment