Sometime you need to find a quick way telling you how long your servers are up.
Here is a little powershell script to get the uptime (in days) of all your servers.
Powershell script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$servers = Get-ADComputer -prop operatingsystem -Filter {operatingsystem -like "*windows server*"} $liveservers = @() $offflineservers = @() $uptimeservers = @() foreach ($server in $servers){ if (Test-Connection -ComputerName $server.name -count 1 -ErrorAction SilentlyContinue){ $liveservers += $server} else{ $offflineservers += $server} } foreach ($server in $liveservers){ $wmi = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $server.name $days = ($wmi.ConvertToDateTime($wmi.LocalDateTime) – $wmi.ConvertToDateTime($wmi.LastBootUpTime)).days $server | Add-Member -MemberType NoteProperty -Name Uptime -Value $null -Force $server.uptime += $days $uptimeservers += $server } |
When you have run this code you can just type,
1 |
$uptimeservers | sort-object uptime | ft name,uptime -AutoSize |
to get a list, sorted by uptime
I find it very handy, I hope you do too.
Thanks for finally writing about >Powershell script to get the
uptime of your servers – ServerFixes <Loved it!
Great blog, ensure that it stays up!