$hash=@{}
$Session = New-Object -ComObject Microsoft.Update.Session
$Searcher = $Session.CreateUpdateSearcher()
$hash[$env:Computername] = $Searcher.QueryHistory(1,1) | select -ExpandProperty Date -ErrorAction Stop
$key = $hash.keys
$re =$hash["$key"]
$return_status=@{ "OK"=0;"WARNING"=1;"CRITICAL"=2;"UNKNOWN"=3 }
$totaltime = ((get-date) - $re).days
if ($totaltime -lt 60) {
write-host "$totaltime days and last patch time is: $re"
exit $return_status["OK"]
}
elseif ($totaltime -ge 60 -and $totaltime -lt 90) {
write-host "$totaltime days and last patch time is: $re"
exit $return_status["WARNING"]
}
elseif ($totaltime -ge 90) {
write-host "$totaltime days and last patch time is: $re"
exit $return_status["CRITICAL"]
}
else {
write-host "OS patch days cant be determined"
exit $return_status["UNKNOWN"]
}
Powershell check server patch status
最新推荐文章于 2021-06-22 20:26:46 发布