See correction to this article

Creating and Deleting Nodes
The most obvious examples of new configuration data that you might need to create are new Web sites or virtual directories. The script that Listing 7, page 60, shows creates a virtual directory in the default Web site when you invoke the script with the virtual directory name and a path to the virtual directory's contents. The script takes two arguments from the command line: the name of the new virtual directory and the physical path. (If these two parameters aren't passed to the script, it terminates.) The script calls the GetObject function to retrieve an object from an existing metabase path, then calls the IADsContainer interface's Create method to create a new node. (For more information about the ADSI IADsContainer interface, see "Related Reading.") This method also takes two arguments: the new node's class and name. The script then sets the physical path and calls SetInfo() to commit the changes. All other properties are inherited from the parent nodes.

Deleting a node is similar to creating it. This task uses the IADsContainer interface's Delete method to perform the delete operation, as Listing 8 shows. In this example, the script takes only one argument: the name of the virtual directory to delete. The script uses the GetObject function to locate the parent node, then uses the IADsContainer Delete method to delete the virtual directory.

Querying for Data
Suppose you want to know where a particular property resides and whether the property is set. For example, suppose you want to determine the level of security compliance on your IIS machine by making sure that your sites and virtual directories allow only a particular type of authentication. To accomplish such tasks, you can use the GetDataPaths function. GetDataPaths returns paths (e.g., IIS://localhost/w3svc/1/root) to all locations in which a specified property exists.

Listing 9 shows a sample script that uses the GetDataPaths method to look up all sites and virtual directories that allow anonymous access. As usual, the script begins by retrieving an object, in this case, the query starting point. (The query will search all subnodes of the specified object.) The script then calls the GetDataPaths method, which takes a string that specifies the property we're looking for. The second argument specifies whether we're looking for any property or only inheritable properties. The GetDataPaths method returns an array of paths, as Figure 3 shows. These results reveal that anonymous authentication is set on the IIS://localhost/W3SVC and IIS://localhost/W3SVC/1/ROOT nodes. To turn off anonymous access, you can use these paths as arguments for additional GetObject calls, as the extended script in Listing 10 shows.

Get Busy
Automating IIS administration can be a big timesaver and a rewarding experience, especially if you administer multiple IIS sites. When you understand the IIS metabase's logical structure and know how to get, set, create, delete, and query IIS configuration data, you can start using your own IIS scripts. Of course, you'll want to add to your scripts some error-handling and parameter-validation functions, which we omitted for the sake of simplicity, but other than that, you're ready to script IIS.




Related Reading
ADSI
IIS ADSI Provider Reference
http://msdn.microsoft.com/library/en-us/iisref/htm/ref_prog_iaorefcompu.asp

Core ADSI interfaces
http://msdn.microsoft.com/library/en-us/netdir/adsi/iadsopendsobject.asp

Constants used in IIS ADSI provider
http://msdn.microsoft.com/library/en-us/iisref/htm/ref_prog_iaorefconstant.asp

ADSI container object functions
http://msdn.microsoft.com/library/en-us/netdir/adsi/iadscontainer.asp

ADSI Administration with ADSUTIL
http://msdn.microsoft.com/library/en-us/iisref/htm/adsiadministrationwithadsutilvbs.asp

IIS 6.0 Direct Metabase Edit feature
http://msdn.microsoft.com/library/en-us/iisref/htm/editwhilerunning.asp

JSCRIPT
HOWTO: Use JScript or JavaScript to Traverse
Through a Collection
http://support.microsoft.com/?kbid=229693

How to convert a VBArray to a JScript Array
http://msdn.microsoft.com/library/en-us/script56/html/js56jsmthtoarray.asp

METABASE EDITING TOOLS
IIS 6.0 Resource Kit (includes Metabase Explorer)
http://www.microsoft.com/downloads/details.aspx?
familyid=56fc92ee-a71a-4c73-b628-ade629c89499&displaylang=en

MetaEdit for IIS 4.0
http://download.microsoft.com/download/
iis50/utility/5.0/nt45/en-us/mtaedt22.exe



End of Article

Prev. page     1 2 3 4 [5]     next page -->
CORRECTIONS TO THIS ARTICLE:
In Brett Hill and Thomas Deml's "Scripting IIS Administration" (December 2003, http://www.win netmag.com, InstantDoc ID 40713), a figure was identified incorrectly. In the print article, Figure 4 should be listed as Figure 3. We apologize for any inconvenience these errors might have caused.




You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

This example is in error "notepad %windir%\system32\inetsrvmetabase.xml" there is a missing "\" between "..\inetsrv" and "metabase.xml"

Roy E Jensen

In the middle of page 4, in

"...To find a site ID for an IIS 5.1 site, run the findweb.vbs script, which resides by default in the %windir%\Inetpub\Adminscripts folder...",

the script actually resides by default in c:\Inetpub\Adminscripts folder.

Hongliang Qiang

Found these articles very intuitive, thanks very much.

Anonymous User

Article Rating 5 out of 5

 
 

ADS BY GOOGLE