How to quickly obtain data from multiple workstations
Your company is purchasing a new application, so you need to make sure that 500 workstations have a certain service pack level installed on thema common task that script-savvy network administrators can easily perform. Typically, .bat and .cmd scripts that perform a task against a list of workstations consist of one line that performs the task and supportive code that connects to the workstation and returns error codes. Wouldn't it be nice if you didn't have to write the supportive code over and over again? A good practice is to reuse code that has already been tested and proven, but keeping track of numerous code snippets can be a challenge.
If you find yourself in this situation, try keeping just one master script that you can add operations to as needed. Letting one script grow in this fashion keeps your code centralized and within easy reach. Plus, it's truly reusable codenot copies of code in multiple scripts that can become outdated. Ideally, master scripts
- work off a list of workstations
- test each workstation to see whether it's a valid machine and powered on
- connect to each workstation
- perform whatever task you need
- log results and error codes
In .bat or .cmd scripts, you typically want code that you can implement easily and quickly. Thus, the master script must start out and remain easily modifiable. I created an easily modifiable script called Chkws, which I've tested on Windows NT 4.0 Service Pack 6 (SP6) through Windows 2000 SP2. Let's look at how Chkws works and how to add operations to it.
How Chkws Works
As the following syntax shows, the command to launch Chkws takes at least two arguments:
chkws [list.txt] [command]
where list.txt is the name of the file that contains the list of workstation names (one name per line) and command is a keyword that specifies the operation to perform. The number of arguments can increase as you find new operations to perform. For example, I initially wrote Chkws to determine which version of Microsoft Internet Explorer (IE) was installed on workstations. I later expanded the script to perform other operations, such as reporting the machine's last reboot, testing whether each workstation is on the network, returning the machine's media access control (MAC) address, using Wake on LAN (WOL) to power on the workstation, checking settings for Symantec's Norton AntiVirus and LiveUpdate, installing Tivoli agents, and rebooting the workstation.