IIS Scripting Solutions

Adsutil.vbs is a handy script that you can use to automate the administration of your Web sites.

Ken Spencer

November 11, 2001

5 Min Read
ITPro Today logo in a gray background | ITPro Today


Using the adsutil.vbs script

IIS comes with a handy script called adsutil.vbs that you can use to automate the administration of your Web sites. This generic script lets you programmatically perform many common IIS administrative tasks, including creating new Web sites; starting, stopping, pausing, and unpausing Web servers; and creating, filling, and deleting Active Server Pages (ASP) application folders. You can use adsutil.vbs to automate tasks on local and remote servers. This script is handy for working with IIS because you only need to provide the necessary parameters to execute the script. You can even use the script with batch files to achieve more functionality.

Before using adsutil.vbs, you need to be aware of a few security implications. To avoid security problems, you should not store adsutil.vbs (or any other administrative script) on a production server. A better approach is to store the script in a location that only administrators can access. In addition, you must be an administrator to perform most of the functions possible with adsutil.vbs.

By default, adsutil.vbs resides in the C:inetpubadminscripts folder. You can access the script three ways:

  • You can place the folder that contains the script in the system path. You can then use the script from any location on the disk.

  • You can create a shortcut to the script by specifying its full path and the necessary parameters.

  • You can access the script from the command prompt if you use the cd command to change the current directory to the directory in which the script resides (C:inetpub adminscripts, by default).

Let's look at several simple tasks you can automate with adsutil.vbs. Then, let's explore how to use adsutil.vbs with batch files to achieve even more functionality.

Automating Tasks Is Just a Couple of Commands Away
As I mentioned earlier, adsutil.vbs is a generic script. Thus, when you run the script, you need to include parameters that specify the tasks you want the script to perform. For example, you can use adsutil.vbs to retrieve data about a Web server or site. Suppose you want to determine the port to which Web site number 1 on the WebServerCo1 server binds. You can use adsutil.vbs to determine the port by issuing the commands

cd inetpubadminscriptsCscript.exe adsutil.vbs GET   W3SVC/1/ServerBindings  -s:WebServerCo1

The first command changes the current directory to the directory that contains the script. The second command runs the script. The second command's parameter GET W3SVC/1/ServerBindings —s:WebServerCo1 is a command in and of itself. The GET command tells the script to retrieve data. The path that follows (i.e., W3SVC/1/ServerBindings) specifies what data to retrieve and where to retrieve it. The W3SVC portion of the path tells the script to access the Web server. The value of 1 tells the script that you're interested in the first Web site on that server, and ServerBindings tells the script to retrieve the server binding for that Web site. The optional —s switch specifies the server's name. You use this switch when you want to access a remote machine.

Figure 1, page 13, shows sample output from running these two commands. This output tells you that Windows Script Host (WSH) was used to run the script and that Web site number 1 (in this case, the Default Web Site) is bound to port 80.

You can use adsutil.vbs to not only retrieve data about Web servers and sites but also manipulate those Web servers and sites. For example, you can start a Web server by issuing the command

Cscript.exe adsutil.vbs START_SERVER W3SVC/1

The START_SERVER command tells the script to start the server that the path specifies. You can stop a server by replacing the START_SERVER command with the STOP_SERVER command. You can also pause and unpause a server with the PAUSE_SERVER and CONTINUE_SERVER commands, respectively. To start, stop, pause, and unpause remote servers, you can add the —s switch and specify the remote server's name, as you did with the GET command.

Using Batch Files
Now let's look at how to automate the use of adsutil.vbs with batch (.bat or .cmd) files. For example, the batch file bouncemany.bat that Listing 1, page 13, shows uses adsutil.vbs to stop and start three servers. This batch file is handy, but you won't know whether the servers stopped and started successfully unless you watch the commands execute in the console window. A better approach is to capture the output of the batch file's commands by appending the results to a log. Listing 2, page 13, contains a new version of the batch file, bouncemany2.bat, that generates such a log called bounce many.log. The log notes the servers being accessed and the status of each command. The Echo commands in bouncemany2.bat create headers and delimiters to make the log easier to read.

Figure 2 shows the first few lines of a sample log. The log excerpt shows an example of the type of error message you'll receive if the script tries to access a server that's unavailable.

Any time you need to bounce servers, you can simply run bouncemany2.bat and the servers will automatically shut down and restart. You can execute bouncemany2.bat two ways. You can include the script's full path in a command such as

C:>c:inetpubadminscriptsbouncemany2.bat

Or, you can first use the cd command to change the current directory to the directory that contains the script, then use only the script's filename in the command to launch the script:

C:inetpubadminscripts>bounce many2.bat

With either option, you can execute the script from anywhere on a system that has access to a directory containing a copy of adsutil.vbs.

A Good Tool to Learn
These examples show the power of adsutil.vbs. You can use adsutil.vbs to automate many more tasks, and you can use batch files to automate the use of adsutil.vbs. If you're going to learn how to use only one IIS script, adsutil.vbs is a good choice. You can find out more information about how to use this script at http://www.microsoft.com/windows2000/en/advanced/iis/default.asp?url=/windows2000/en/advanced/iis/htm/adminsamples/iiasabt.htm.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like