以下檢查正常運行時間。我沒有叮叮的一種情況(現在除外)是,如果服務器可以ping通,但無法獲得正常運行時間 - 如果出現這種情況,我需要下面的腳本來出錯。我想不出如何做到這一點 - 任何想法?檢查ping和正常運行時間?
CODE:
#clear
$Computers = Get-Content "E:\DATA\PS_Jobs\Patching_Uptime\Saturday_Servers.txt"
Foreach($computer in $Computers)
{
if (Test-Connection -ComputerName $computer -Quiet)
{
$LastBoot = (Get-WmiObject -Class Win32_OperatingSystem -computername $computer).LastBootUpTime
$sysuptime = (Get-Date) – [System.Management.ManagementDateTimeconverter]::ToDateTime($LastBoot)
$days = $sysuptime.Days
$DaystoHours = ($sysuptime.Days)*24
$hours = $sysuptime.hours
$TotalHours = $DaystoHours + $hours
if($TotalHours -gt '12')
{
Write-EventLog -LogName WinLondonUptime -Source Uptime -EntryType Error -EventId 5 -Message "$computer - FAILED - Servers Uptime is GREATER then 12 hours or not contactable - Uptime is $days Days and $hours Hours - This is the Saturday patching run"
}
else
{
Write-EventLog -LogName WinLondonUptime -Source Uptime -EntryType Information -EventId 4 -Message "$computer - SUCCESS - Servers uptime is less than 12 hours - Uptime is $days Days and $hours Hours - This is the Saturday patching run"
}
}
else
{
Write-EventLog -LogName WinLondonUptime -Source Uptime -EntryType Error -EventId 5 -Message "$computer - FAILED - Server is not contactable - This is the Saturday patching run"
}
}
雖然我不確定這是否是偏離主題,但我認爲您有更好的機會在[su]上獲得PowerShell的答案。 –
您可以計算運行時間越來越最長的運行過程或查詢系統事件日誌獲取事件ID 6005 –
覺得我問這個稍微不正確 - 很多你在想我想的正常運行時間 - 這是不正確 - 上面的代碼確實得到了正常運行時間。我特別詢問何時UPTIME不可用於我希望它出錯的特定服務器....即使服務器已啓動並執行ping操作。 – lara400