Thursday, 2 April 2009

Check-Uptime

The Need:
There are several occasions when I need to check the uptime on a number of servers.


The Script:
$Servers = Get-Content "c:\Servers.txt"
Function Check-Uptime {
forEach($Server in $Servers)
{
$wmi = gwmi Win32_OperatingSystem -comp $Server
$BootTime = $wmi.ConvertToDateTime($wmi.Lastbootuptime)
[TimeSpan]$Uptime = New-TimeSpan $BootTime $(get-date)
Write-host $Server :Uptime: " $Uptime.days "Days" $Uptime.hours "Hours" $uptime.minutes "Minutes" $uptime.seconds "Seconds"
}}
Check-Uptime

No comments: