您的位置:首页 > 运维架构 > Shell

Powershell check server patch status

2016-05-13 15:04 405 查看
$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"]
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息