Build precise queries to find exactly what you need
Press ESC to close
Your review has been submitted and is pending approval.
Script to calculate the Days since last Windows Update which is understandable for every Manager :-} should be called via NRPE/NSClient++ inspired by [email protected] check_win_lastupdate.vbs but with using Microsoft.Update.Session instead of Registry. Registry query not working in W2016 or W10.
Current Version
1.o
Last Release Date
2018-01-26
Owner
Peter Luetke-Bexten
License
GPL
Compatible With
################################################################################## # # NAME: check_win_last_update.ps1 # # AUTHOR: Peter Luetke-Bexten # COAUTHOR: Christoph Hamschmidt # EMAIL: peter.luetke-bexten (at) benteler.com # # COMMENT: # Script to calculate the Days since last Windows Update # which is understandable for every Manager :-} # should be called via NRPE/NSClient++ # inspired by [email protected] check_win_lastupdate.vbs # but with using Microsoft.Update.Session instead of Registry. # Registry query not working in W2016 or W10. # # NSCLIENT.ini: # check_win_lastupdate = cmd /c echo scriptspowershellcheck_win_last_update.ps1 $ARG1$ $ARG2$ ; exit($lastexitcode) | "C:WindowsSystem32WindowsPowerShellv1.0powershell.exe" -noninteractive -noprofile -ExecutionPolicy unrestricted -command - # # NRPE Check: # check_nrpe -H targethost -p 5666 -t 120 -u -c check_win_lastupdate -a 35 70 # # CHANGELOG: # 1.0 20180126 - initial version # ################################################################################
# Script calculates curent date and date of last Windows Update Installation
## Arguments $wldays = $args[0] $cldays = $args[1]
## ReturnStates $returnStateOK = 0 $returnStateWarning = 1 $returnStateCritical = 2 $returnStateUnknown = 3
## Get lasat installed update and select date as object $Session = New-Object -ComObject Microsoft.Update.Session $Searcher = $Session.CreateUpdateSearcher() $HistoryCount = $Searcher.GetTotalHistoryCount() ## http://msdn.microsoft.com/en-us/library/windows/desktop/aa386532%28v=vs.85%29.aspx $DatelastInstall = $Searcher.QueryHistory(0,$HistoryCount) | ForEach-Object {$_} | Select-Object -First 1 | Select-Object -Property Date
## Get actual date $Datenow = Get-Date
## Get number of days since list install $DayslastInstall = ($Datenow - $DatelastInstall.date).Days $DayslastInstalldate = ($Datenow.Date - $DatelastInstall.Date).Days
## Debug # $DatelastInstall.ToString() # $DatelastInstall # $DatelastInstall.date # $Datenow # $Datenow.date # $DayslastInstall # $DayslastInstalldate
if (!$wldays) { echo "Usage: check_win_last_update.ps1 <WARN threshold days> <CRIT threshold days>" exit 3 }
# if ($DayslastInstall) { if ($DayslastInstalldate -eq 0) { Write-Host "OK - Patches applied $DayslastInstalldate days ago at $($DatelastInstall.Date)" exit $returnStateOK } elseif ($DayslastInstall -lt $wldays) { Write-Host "OK - Patches applied $DayslastInstalldate days ago at $($DatelastInstall.Date)" exit $returnStateOK } elseif ($DayslastInstall -lt $cldays) { Write-Host "WARNING - Patches applied $DayslastInstalldate days ago $($DatelastInstall.Date)" exit $returnStateWarning } elseif ($DayslastInstall -gt $cldays) { Write-Host "CRITICAL - Patches applied $DayslastInstalldate days ago $($DatelastInstall.Date)" exit $returnStateCritical } else { Write-Host "UNKNOWN" exit $returnStateUnknown } # } else { else { Write-Host "UNKNOWN - unable to get date of last Widows Update Installation" exit $returnStateUnknown }
You must be logged in to submit a review.
To:
From: