Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Enumerating Metabase Properties Using WMI

IIS 6.0

There are times when you want to view all properties at a specific node without having to open IIS Manager, the metabase file, or CIM Studio.

IIS 5.1 and earlier: The IIS WMI provider is not available.

The following code uses the VBScript For...Each loop and the JScript Enumerator object to display all the properties for the root virtual directory of the Default Web Site. In the VBScript code, On Error Resume Next is used because some of the properties are objects, or arrays of objects, that need extra code to be displayed.

On Error Resume Next 
set providerObj = GetObject("winmgmts://localhost/root/MicrosoftIISv2") 
set IIsWebVirtualDirObj = providerObj.get("IIsWebVirtualDir='W3SVC/1/ROOT'") 
set IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'") 
 
WScript.Echo "Read only properties of W3SVC/1/Root:" 
For Each Property in IIsWebVirtualDirObj.Properties_ 
  WScript.Echo Property.Name & " = " & Property.Value 
Next 
WScript.Echo 
WScript.Echo "Read/Write properties of W3SVC/1/Root:" 
For Each Property in IIsWebVirtualDirSettingObj.Properties_ 
  WScript.Echo Property.Name & " = " & Property.Value 
Next 
var providerObj = GetObject("winmgmts://localhost/root/MicrosoftIISv2"); 
var IIsWebVirtualDirObj = providerObj.get("IIsWebVirtualDir='W3SVC/1/ROOT'"); 
var IIsWebVirtualDirSettingObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/ROOT'"); 
 
WScript.Echo("Read only properties of W3SVC/1/Root:"); 
var e = new Enumerator(IIsWebVirtualDirObj.Properties_); 
for(; ! e.atEnd(); e.moveNext()) 
{ 
  var Property = e.item(); 
  WScript.Echo(Property.Name + " = " + Property.Value); 
} 
WScript.Echo(); 
WScript.Echo("Read/Write properties of W3SVC/1/Root:"); 
var e = new Enumerator(IIsWebVirtualDirSettingObj.Properties_); 
for(; ! e.atEnd(); e.moveNext()) 
{ 
  var Property = e.item(); 
  WScript.Echo(Property.Name + " = " + Property.Value);
} 

To experiment with this example, change the bolded text in the code to other values that are listed in the Access Locations table on the KeyType page. Remember that the IIS Admin object type must match the metabase path.

To turn this into a tool that would take parameters for the machine name, IIS Admin object type, and metabase path, you could change the code above to the code below. Bolded items are new.

On Error Resume Next 
' Get the arguments. 
set WshArgs = WScript.Arguments 
 
if WshArgs.Length = 3 then 
 
  dim machineName, adminObjType, metabasePath 
  machineName = WshArgs(0) 
  adminObjType = WshArgs(1) 
  metabasePath = WshArgs(2) 
 
  set providerObj = GetObject("winmgmts://" & machineName & "/root/MicrosoftIISv2") 
  set IIsWebVirtualDirObj = providerObj.get(adminObjType & "='" & metabasePath & "'") 
  set IIsWebVirtualDirSettingObj = providerObj.get(adminObjType & "Setting='" & metabasePath & "'") 
 
  WScript.Echo "Read only properties of " & metabasePath & ":" 
  For Each Property in IIsWebVirtualDirObj.Properties_ 
    WScript.Echo Property.Name & " =" & Property.Value  
  Next   
  WScript.Echo WScript.Echo "Read/Write properties of " & metabasePath & ":" 
  For Each Property in IIsWebVirtualDirSettingObj.Properties_ 
    WScript.Echo Property.Name & " = " & Property.Value 
  Next 
 
  ' end of if WshArgs.Length = 3 then 
 
else 
  WScript.Echo "Usage:" 
  WScript.Echo "cscript /nologo " & WScript.ScriptName & " <computer name> <admin object type> <metabase path>" 
  WScript.Echo "Example:" 
  WScript.Echo "cscript /nologo " & WScript.ScriptName & " MyMachine IIsWebVirtualDir W3SVC/1/Root" 
end if 
// Get the arguments. 
var WshArgs = WScript.Arguments; 
 
if (WshArgs.Length == 3) { 
 
  var machineName = WshArgs(0); 
  var adminObjType = WshArgs(1); 
  var metabasePath = WshArgs(2); 
 
  var providerObj = GetObject("winmgmts://" + machineName + "/root/MicrosoftIISv2"); 
  var IIsWebVirtualDirObj = providerObj.get(adminObjType + "='" + metabasePath + "'"); 
  var IIsWebVirtualDirSettingObj = providerObj.get(adminObjType + "Setting='" + metabasePath + "'"); 
 
  WScript.Echo("Read only properties of " + metabasePath + ":"); 
  var e = new Enumerator(IIsWebVirtualDirObj.Properties_); 
 
  for(; ! e.atEnd(); e.moveNext()) { 
    var Property = e.item(); 
    WScript.Echo(Property.Name + " = " + Property.Value);  
  }   
  WScript.Echo();  
  WScript.Echo("Read/Write properties of " + metabasePath + ":"); 
  var e = new Enumerator(IIsWebVirtualDirSettingObj.Properties_); 
  for(; ! e.atEnd(); e.moveNext()) 
  { 
    var Property = e.item(); 
    WScript.Echo(Property.Name + " = " + Property.Value); 
  } 
 
} // end of if (WshArgs.Length == 3) 
else { 
  WScript.Echo("Usage:"); 
  WScript.Echo("cscript /nologo " + WScript.ScriptName + " <computer name> <admin object type> <metabase path>"); 
  WScript.Echo("Example:"); 
  WScript.Echo("cscript /nologo " + WScript.ScriptName + " MyMachine IIsWebVirtualDir W3SVC/1/Root"); 
} 
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.