On the journey to create a successful script, there are sometimes unexpected detours in the
road. Sometimes a script just comes together and works on the first try. Other times, there are
challenges at every turn. I have to admit that UptimeReport.bat didn’t work correctly on the first
or even the second try. I ran into problems finding utilities that provided the information I
needed, sorting the utilities’ output, dealing with errors, and getting output displayed in a
meaningful format. My struggles revealed some real-world problems that scripters can face. By
sharing the lessons I learned, I hope you can avoid similar problems.
Make sure a tool’s output is consistent across OSs. The first time I got UptimeReport.bat
working, a savvy systems administrator looked at the report and questioned some of the uptime
numbers. After some investigation, I realized that my script was mysteriously introducing some
bogus numbers into the report. It took only a few minutes of testing to determine that the
Uptime.exe utility in the Microsoft Windows 2000 Server Resource Kit reports uptime results
differently on Windows Server 2003 and Windows 2000 systems. When you use the For
command to extract data from Uptime.exe’s output, these differences cause problems. For this
reason, I used Sysinternals’ PsInfo tool. It has a consistent output format that works well with
the For command. . . .