Metabase Hierarchy
As you begin to delve into the metabase, the first thing you encounter is its hierarchical nature. Most tasks you want to accomplish with a script involve setting or retrieving a property at a specific node in the hierarchy. Be certain to keep this hierarchy in mind when writing scripts, or you might unintentionally change child elements' properties.
Let's use Metabase Explorer to accomplish the same task as iispath.jslocating your default Web site's path. To do so, we'll explore the pathname (i.e., IIS://localhost/W3SVC/1/ROOT) that we used in iispath.js. Expand the Web server object, then expand the LM (LM stands for local machine, represented by localhost in iispath.js's pathname argument), W3SVC, 1, and ROOT nodes. When you select the ROOT node, the right-hand pane displays several properties. The Path property appears in the right-hand pane, as Figure 2 shows.
Now, let's change iispath.js so that its results display some of the other properties you see in Metabase Explorer. For example, to output the default documents, modify the one-line script to read as follows:
WScript.Echo ("Default Documents: "
+ GetObject
("IIS://localhost/W3SVC/1/ROOT")
.DefaultDoc);
Notice that both versions of iispath.js use the JScript GetObject function to retrieve IIS configuration data. This function accesses an object of a specific class (aka Key Type), depending on the pathname argument you use. (When you use Metabase Explorer to view an object's properties, the object's class appears as the KeyType.) Table 1 shows some examples of the classes that the GetObject function can access. (The IIS documentation describes the properties and methods that each class supports, these properties' functions, and how to change the properties.) After you access an object derived from one of these classes, you can query the object as to its properties so that you can determine specific settings, such as a virtual directory's path or a Web site's IP address. You can use scripts to set values for these settings or, in some cases, invoke predefined actions, called methods (e.g., the Backup method, which backs up the metabase). Let's examine the objects at each level of the hierarchy in our example pathname.
The machine node (IIsComputer class). Providing the IIS://localhost pathname as an argument to the GetObject function causes the script to return an object with the class IIsComputer; the object represents the machine node. This class has only a few properties and machine-specific methods, such as the Backup and Restore methods.
Listing 1 shows a sample script that uses the Backup method to back up the IIS metabase. After you run this script, the file MyBackup.md0 will appear in the system's %windir%\system32\inetsrv\metaback directory. The backup function lets you specify a backup-version number. If you don't want to bother with this specification, you can set the number to -1, as the code at callout A in Listing 1 shows, and IIS will automatically select the next available version number.
Listing 2 shows a sample script that uses the Restore method to restore the backup. The code at callout A in Listing 2 tells IIS to use the highest existing backup version. If you want to restore a particular backup version, you can replace "-2" with a specific version number (e.g., "100"). To verify that your scripts' backup and restore functionality is working, invoke the backup script, delete a test virtual directory, then invoke the restore script and verify that the deleted virtual directory is restored.
Prev. page
1
2
[3]
4
5
next page