Subscribe to Windows IT Pro
August 13, 2002 12:00 AM

Query Workstations the Easy Way

Windows IT Pro
InstantDoc ID #26054
Rating: (0)
Downloads
26054.zip

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 them—a 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 code—not 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.

Related Content:

ARTICLE TOOLS

Comments
  • brian
    9 years ago
    Feb 08, 2003

    I'm trying to work through the code but my XP system seems to have a problem with the following code in callouts B & D in Listing 1:


    >nul & if not errorlevel 1


    The program stops at these points with a syntax error. I can't seem to figure out what is going on here. Any advice?




    That is an effect of the way the code is displayed in the listing. That line you posted and the line after it needs to be concatenated instead of broken up. I tested it with Windows XP and it worked fine after that change was made.--James Adair



You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.