下面检查正常运行时间。我没有想到的一个条件(现在除外)是服务器是否可以被 ping 通但无法正常运行 - 如果是这种情况,我需要下面的脚本来出错。我想不出怎么做——有什么想法吗?
代码:
#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"
}
}