Created
March 2, 2015 10:27
-
-
Save hemebond/29530d88f5753fd0b85c to your computer and use it in GitHub Desktop.
PowerShell script checks for available updates and returns the result in the standard monitoring plugin output format.
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
$Session = New-Object -ComObject "Microsoft.Update.Session" | |
$Searcher = $Session.CreateUpdateSearcher() | |
$Result = $Searcher.Search("IsInstalled = 0 and IsHidden = 0") | |
$Updates = $Result.Updates | |
$Total = $Updates.Count | |
$Critical = @($Updates | Where-Object {$_.MsrcSeverity -eq 'Important' -or $_.MsrcSeverity -eq 'Critical'}).Count | |
if ($Critical -gt 0) { | |
$CheckResult = 'CRITICAL' | |
$ExitCode = 2 | |
} | |
elseif ($Total -gt 0 ) { | |
$CheckResult = 'WARNING' | |
$ExitCode = 1 | |
} | |
else { | |
$CheckResult = 'OK' | |
$ExitCode = 0 | |
} | |
Write-Output "$($CheckResult): $($Total) updates available ($($Critical) critical updates)." | |
Exit $ExitCode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment