Windows Update pending count powershell
Reports how many updates are currently pending install. Use to find machines drifting behind on patches.
Placeholders only. Before running, replace
YOUR_URL with your capture endpoint's POST URL
.
(Open this page from your capture object to have these auto-filled.)
# windows-update-pending.ps1 — count of pending Windows updates.
$Url = "YOUR_URL/wsus"
$Session = New-Object -ComObject "Microsoft.Update.Session"
$Searcher = $Session.CreateUpdateSearcher()
try {
$Pending = ($Searcher.Search("IsInstalled=0 and Type='Software'")).Updates.Count
$Reboot = ((New-Object -ComObject "Microsoft.Update.SystemInfo").RebootRequired) -as [bool]
} catch {
$Pending = -1
$Reboot = $false
}
$Body = (@{
hostname = $env:COMPUTERNAME
pending_count = $Pending
reboot_required = $Reboot
}) | ConvertTo-Json -Compress
Invoke-RestMethod -Uri $Url -Method Post -Body $Body `
-ContentType "application/json" -TimeoutSec 15 | Out-Null
Recommended pairing
Add a capture.value check to this capture object.
json_path = pending_count, op = >, threshold = 5 (tune for your patching cadence).
What is the filename?
windows-update-pending.ps1 — this is the suggested name for the downloaded file. Rename freely if you prefer.
site1.erralert.com