Powershell check server patch status

来源:互联网 发布:什么是淘宝黑搜 编辑:程序博客网 时间:2024/04/30 15:07
    $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"]    }

0 0