Managing a homogeneous Windows server environment with PsExec

The Enrich team has a suite of automated UI tests that run as part of our continuous integration process. UI tests tend to be slow in nature so we use a server farm of 14 identical virtual machines, each running a mstest agent, to speed things up. One challenge I face is how to manage all of the identical Windows systems in an efficient, automated manner.  An example of this is needing to copy a database backup and restore it to each server periodically.

Here’s a simple way to administer the group of servers sort of like a Single instruction, multiple data (SIMD) system using freely available tools.

First download Mark Russinovich’s, PsExec which lets you run commands on remote systems:

PsExec is a light-weight telnet-replacement that lets you execute processes on other systems, complete with full interactivity for console applications, without having to manually install client software.

This utility will let you forward a command to a remote system for execution and is the foundation of this technique.  The fact that this tool doesn’t require an install on the environments makes setup a breeze. However, you may need to make a few security/firewall changes on each system to get it the communication between systems to work.

Next, I’ve devised a simple batch file (VMs-cmd.bat) that I can pass a command to that will then be executed in sequence on every server in the environment. For example, the following command will create the c:\whatever directory on every server:

VMs-cmd "mkdir c:\whatever"

Here’s the source code for VMs-cmd.bat:

SET VMs=01, 02, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14
FOR %%t in (%VMs%) DO (PsExec.exe \\YouServer-%%t -u username -p password c:\windows\system32\cmd.exe /C %1)

Note that:

  • This assumes a naming convention of YourServer-XX where XX is the server number. Update the code with your server naming convention and numbers.
  • You will need to replace the username and password in the batch file

About this entry