We have a problem with people in our company leaving their computer running 24/7 even over weekends. Our corporate policy is to shut down when not in use but that doesn't always happen. So what we have been doing is running a simple script using PsInfo to pull back the uptime of the computers. We export out the list of computers from AD into a text file then use a batch file to go through the list, pull the uptime info, and save it to another text file:
For /F "tokens=*" %%i in (ComputerList.txt) do psinfo uptime -nobanner \\%%i 1>>UptimeResults.txt
Works great but if a computer is not online the default timeout seems to be 60 seconds which can cause the script to take a very long time for hundreds of computers. PsExec itself has a timeout switch you can use but PsInfo doesn't seem to take this into account. Is there another way to either force it to timeout after say 10 seconds or a different program that will do the same thing? Possibly using PsExec directly with the time out switch and some other command? As a side note we have already disabled fastboot so the uptime results are accurate.
Things we have debated but are hoping for a easier solution: Using PsExec and running systeminfo | find "Boot Time"
then analyze the boot time and do some math to get runtime. Getting a old copy of uptime.exe, deploying it to the computers, and using it's output with PsExec. And switching over to a powershell command that would poll WMI for last boot time and again do the math. All seem overly complicated and would rather have the easy but slow solution unless someone else has a better suggestion.
FOR /F %i IN (File.txt) DO WMIC /NODE:"%i" /FAILFAST OS GET LastBootupTime
System information for \\PC4221DA: Uptime: 4 days 23 hours 55 minutes 48 seconds