In this section, you will restore the metabase that was backed up in the previous section.
1. | Open \My Documents\Microsoft Press\VBScriptSBS\Templates\BlankTemplate.vbs in Notepad or your favorite script editor and save it as YourNameImportIISMetaBase.vbs.
|
2. | As the first non-commented line, type Option Explicit.
|
3. | Declare the following variables: strPassword, strFilePath, strSourceMetabasePath, strDestinationMetabasePath, intFlags, locatorObj, providerObj, and computerObj. Your completed Header information section will look like the following:
Option Explicit
Dim strPassword
Dim strFilePath
Dim strSourceMetabasePath
Dim strDestinationMetabasePath
Dim intFlags
Dim locatorObj
Dim providerObj
Dim computerObj
|
4. | Create four constants to control the import behavior. CONST IMPORT_CHILDREN = 0 recursively imports the subkeys of the specified key; CONST IMPORT_INHERITED = 1 imports the inherited properties of the keys; CONSTANT IMPORT_NODE_ONLY = 2 does not import subkeys from the specified file. The last constant is CONST IMPORT_MERGE = 4, which merges the imported keys into the existing configuration instead of completely replacing what previously existed. The code for this looks like the following:
Const IMPORT_CHILDREN = 0
Const IMPORT_INHERITED = 1
Const IMPORT_NODE_ONLY = 2
Const IMPORT_MERGE = 4
|
5. | Assign the password "ExportingPassw0rd" to the strPassword variable.
|
6. | Specify the physical path for the exported metabase by assigning the value of "C:\exported.xml" to the strFilePath variable.
|
7. | Set the strSourceMetabasePath variable to be equal to "/lm/logging/custom logging". This is represented in the Metabase.xml file.
|
8. | Set the strDestinationMetabasePath variable to be equal to "/lm/logging/custom logging". This value can be different from the strSourceMetabasePath variable if required.
|
9. | Set the intFlags to be equal to IMPORT_NODE_ONLY OR IMPORT_INHERITED. This will import only the node with the inherited properties. This section of code looks like the following:
strPassword = "ExportingPassw0rd"
strFilePath = "C:\exported.xml"
strSourceMetabasePath = "/lm/logging/custom logging"
strDestinationMetabasePath = "/lm/logging/custom logging"
intFlags = IMPORT_NODE_ONLY OR IMPORT_INHERITED
|
10. | Set the locatorObj variable equal to the object that comes back to the SWbemLocator object when you use the CreateObject command. This code looks like the following:
Set locatorObj = CreateObject("WbemScripting.SWbemLocator")
|
11. | Set the providerObj variable equal to the object that comes back from using the ConnectServer method of SWbemLocator. The providerObj variable is used to connect to the London server MicrosoftIISv2 namespace. This line of code looks like the following:
Set providerObj = locatorObj.ConnectServer _
("London", "root/MicrosoftIISv2")
|
12. | Set the computerObj variable equal to the object into IIsComputer = <;$QS>LM<;$QS> when you use the Get command of the providerObj. This line of code looks like the following:
Set computerObj = providerObj.Get("IIsComputer = 'LM'")
|
13. | Call the Import method from the Computer object. The Import method requires the variables strPassword, strFilePath, strSourceMetabasePath, strDestinationMetabasePath, and intFlags to be set. This line of code looks like the following:
computerObj.Import strPassword, strFilePath, _
strSourceMetabasePath, strDestinationMetabasePath, intFlags
|
14. | Echo out the results. Include the strFilePath variable and the strDestinationMetabasePath variables as confirmation. Your code could look like the following:
WScript.Echo "Imported the node in " & strFilePath & " to " _
& strDestinationMetabasePath
|
15. | Save and test your file. If it does not perform as expected, compare it to \My Documents\Microsoft Press\VBScriptSBS\ch19\OneStepFurther\ImportIISMetaBase.vbs.
|