Downloads
21557.zip

This month, I show you a simple VBScript program that lists the Web sites on any server to which you have access on your LAN or WAN. The script comes in two versions: listwebappsany.vbs, which Listing 1 shows, and listwebappsanytofile.vbs, which Listing 2 shows. Listwebappsany.vbs displays the number, name, and server name for each Web site on the server or on a remote server if you specify the server's name. The second script performs the same tasks but writes the results to the C:\scripts\listwebapps.txt file. The scripts use Microsoft Active Directory Service Interfaces (ADSI) to talk to the IIS metabase and extract the Web site information. Of course, to execute the scripts successfully, you must have the proper security permissions to the resources that those scripts use (e.g., metabase, file system).

These scripts are useful for discovering the Web sites on a local or remote server either interactively or by calling the script from another application. This versatility lets you inspect or gather information about Web sites on any system to which you have access. In addition, the scripts make it easy to perform the search in one step. Also, the scripts are faster than using Internet Services Manager (ISM) to explore the remote systems. Because the program is written in VBScript, you can paste portions of scripts from other files into the VBScript file to modify it to perform other tasks.

Using Listwebappsany.vbs
You can run listwebappsany.vbs without arguments to display the Web sites on your local system. To display the Web sites on another system, execute the program and specify the name of the remote system as a parameter.

For example, executing the command

ListWebAppsAny

on my notebook computer displays the results that Figure 1 shows. In Figure 1, the name of the server appears as LOCALHOST, which is the default server name and points to the current server. To execute the program on a remote server, use the command

ListWebAppsAny servername

where servername is the server on which you want to list the applications.

If you use the program frequently to look at particular servers, you can create shortcuts to those servers. The easiest way to create the shortcuts is to start with a shortcut to your local server. To create shortcuts that point to other servers, copy the first shortcut, then right-click the shortcut you just created and select Properties. In the shortcut's Property dialog box, change the target to include the name of the server to check. For example, I have a shortcut that points to the Dev32X server, which has the target C:\scripts\listwebappsany.vbs dev32x.

Using Listwebappsanytofile.vbs
Listwebappsanytofile.vbs can search a list of systems and save the results to a file or other source. You execute the program by specifying from 1 to 11 servers as parameters to the command. For example, the command

ListWebAppsAnyToFile localhost  Dev32X

executes the script against two servers (i.e., localhost and Dev32X). This command writes the information that Figure 2 shows to the C:\scripts\listwebapps.txt file. The last line in Figure 2 shows that the commands in the script couldn't find the Dev32X server. Either the results from a server appear in the output file or an error message appears for that server.

Next Month
Listwebappsany.vbs and listwebappsanytofile.vbs demonstrate how powerful ADSI is. You can easily use these two scripts to obtain information from your servers or modify the scripts to change configuration information or other information on your servers by extending them. IIS and ADSI provide a rich architecture for accessing IIS and applications. I'll delve into extending these concepts in future articles.

Listwebappsanytofile.vbs also uses the FileSystem object to write the results of the query to a file. Next month, I'll explore other ways in which you can use adsutil.vbs to automate Web server management.