Compare Windows Patch Baselines With Python and PowerShell
Before you begin
- Applies to:Windows targets with a supported remoting endpoint and a report workstation running Python 3.10 or later.
- Where to start:Open PowerShell 7 or later on the domain management workstation.
- What you need:Have approved WinRM access and an account allowed to read the target servicing keys.
Guide tools
Downloads
Steps
Define the minimum build for each target
Save baseline.json with the FQDNs used by the collector. These builds are illustrative. Use your approved minimum and build family for each OS release.
{ "srv01.example.com": "26100.33822", "srv02.example.com": "26100.33822"}Collect from approved hosts
Run in the directory containing the scripts. The collector uses the existing session identity and remote settings and reads the build, revision, and common servicing reboot keys. Warnings identify failed collection targets. The JSON retains a status row for each. Run small batches and record when each was collected.
.\Collect-WindowsPatchState.ps1 -ComputerName srv01.example.com,srv02.example.com | Set-Content -Encoding utf8 collection.jsonCompare with the baseline
Use the same FQDNs in both files. Hostname matching ignores case and a trailing DNS dot. Duplicate names after normalization are rejected. Expect meets_build_baseline, pending_reboot, below_baseline, wrong_build_family, or a missing or failed collection status. Exit 0 means all targets meet the baseline, 1 means review is needed, and 2 means invalid or unreadable input.
python windows_patch_report.py baseline.json collection.jsonVerify after the maintenance window
VerifyFor a pending reboot, review update history and schedule an approved restart. For failed collection, restore access through your existing management workflow. Recollect after one correction and compare against the same baseline.
References
Your feedback keeps these production procedures accurate and battle-tested.