So what’s your Server’s Uptime
This is a Powershell script to get the last boot from a list of servers provided. The script has two parts, first you need a text file of IP addresses you want to test against. . Once you have your text file name it “Server_List.txt” (without the quotes) and save it to a directory.
Copy the below PowerShell script into a notepad and save it as Server_Uptime.ps1 to the same directory as the text file. (the name could be anything as long as it ends with .ps1)
$Today = Get-Date $Computers = Get-Content Server_List.txt Get-CimInstance -ClassName win32_operatingsystem -ComputerName $Computers | select Caption, Version, csname, lastbootuptime | Export-Csv -Path "Server-Results_$($Today.ToString('MM-dd-yyyy_HH.mm.ss')).csv" -Append
You can double click the script, but I like to see my scripts run in case of errors so I suggest opening PowerShell as Administrator (or Domain Admin depending on you pay-grade and environment) Navigate to the directory and run it by typing the first letters and hitting the “TAB” key. If it auto fills with the script, hit enter and wait. Error will print to screen if any and a file named “Server-Results_With today’s date” will appear with the results.
2012 R2 and Older
For those who have dinosaurs roaming in your racks, which are running older powershell 2.0 and earlier you can try:
systeminfo | find "System Boot Time:"
This command will work at a command prompt.