Listing 1: Excerpt from UptimeReport.bat :ReportWrite :: BEGIN COMMENT :: Write the header to the report file. :: END COMMENT Echo SERVERNAME, Days:Hours:Mins Uptime>>%Outfile4% :: BEGIN CALLOUT A :: BEGIN COMMENT :: Sort the results by minutes. :: END COMMENT "%FsortLoc%" /Numeric <"%Outfile%">"%Outfile2%" :: END CALLOUT A For /F "tokens=2,3 delims=," %%i in (%Outfile2%) Do Echo %%j,%%i>>"%Outfile4%" :: BEGIN COMMENT :: Insert a separation line between the report's top and bottom sections. :: You can remove this code if desired. :: END COMMENT Echo **********,**********,>>%Outfile4% Echo Offline or N/A SERVERS, ERROR DESCRIPTION>>%Outfile4% :: BEGIN COMMENT :: Use the Sort command to list the inaccessible servers alphabetically. :: END COMMENT Sort %Outfile3%>>%Outfile4% :: BEGIN CALLOUT B If /I "%ReportType%"=="htm" "%CsvtoHtmLoc%" "Uptime report" < "%Outfile4%" > "%Outfile5%" :: END CALLOUT B :: BEGIN CALLOUT C :: BEGIN COMMENT :: Use Blat to email the HTML report to the target recipients. :: END COMMENT If /I "%ReportType%"=="htm" "%Blatutil%" "%messagefile%" -attach "%Outfile5%" -s "Uptime Report" -server %SMTPsrvr% -f %From% -t %Recipients% & Goto :Finish :: BEGIN COMMENT :: Use Blat to email the CSV report to the target recipients. :: END COMMENT "%Blatutil%" "%messagefile%" -attach "%Outfile4%" -s "Uptime Report" -server %SMTPsrvr% -f %From% -t %Recipients% :: END CALLOUT C :Finish :: BEGIN COMMENT :: Clean up the temporary files. :: END COMMENT If Exist "%temp%\*uptime*.*" Del "%temp%\*uptime*.*" Echo Run complete! Goto :EOF :OUQuery :: BEGIN COMMENT :: Use an OU query to determine the servers to check. :: END COMMENT ::BEGIN CALLOUT D SetLocal EnableDelayedExpansion If Exist %Exclude% For /F "tokens=*" %%i in (%Exclude%) Do (Set excl=!excl! ^^^^^| Find /I /V "%%i") Set string=!excl! SetLocal DisableDelayedExpansion :: END CALLOUT D :: BEGIN CALLOUT E :: BEGIN COMMENT :: Run Dsquery with the exclusions just identified. :: END COMMENT If Exist %Exclude% For /f "tokens=*" %%i in ('%DsqLoc% computer -limit 0 -o rdn -scope subtree %OUtarget% %string%') Do (Set Server=%%i) & (Call :pingit) :: BEGIN COMMENT :: Run Dsquery with no exclusions. :: END COMMENT If Not Exist %Exclude% For /f "tokens=*" %%i in ('%DsqLoc% computer -limit 0 -o rdn -scope subtree %OUtarget%') Do (Set Server=%%i) & (Call :pingit) :ListQuery :: BEGIN COMMENT :: Use an input list to determine the servers to check. :: END COMMENT For /F "usebackq tokens=1" %%i in ("%List%") Do (Set Server=%%i) & (Call :pingit) Goto :EOF :: END CALLOUT E :: BEGIN CALLOUT F :pingit :: BEGIN COMMENT :: Strip off any quotes around server names. :: END COMMENT Set Server=%Server:"=% Set response= For /F "tokens=1" %%i in ('ping -n 1 -w 10 %Server% ^| Find "Reply"') Do (Set response=Online) & (Call :testup) If Not Defined response Echo %Server%,Offline!>>%Outfile3% Goto :EOF :testup For /F "tokens=1,2,3,4,5,6" %%i in ('%PsLoc% \\%Server% uptime ^|Find "Uptime:"') Do (Set Days=%%j) & (Set Hours=%%l) & (Set Mins=%%n) & (Goto :last) Echo %Server%,Server N/A>>%Outfile3% & Goto :EOF :: END CALLOUT F :last :: BEGIN CALLOUT G If "%Days%:%Hours%:"=="Error:uptime:" Echo %Server%,Uptime Acquisition Error!>>%Outfile3% & Goto :EOF :: END CALLOUT G ::BEGIN CALLOUT H :: BEGIN COMMENT :: Convert uptime statistic to minutes. :: END COMMENT Set /A TotMins=(%Days%*1440)+(%Hours%*60)+%Mins% Echo %TotMins%,%Days%:%Hours%:%Mins%,%Server%>>%Outfile% :: END CALLOUT H Goto :EOF