2

I'm trying to follow the guides for accessing IIS 6 using WMI but I'm having trouble working out how to translate the Get method of SWbemServices as Get-WmiObject doesn't seem to use the same path syntax (Describing the Location of a WMI Object).

The example I was following is located on Connecting to the WMI Provider:

' Method 1
set locatorObj = CreateObject("WbemScripting.SWbemLocator") 
set providerObj = locatorObj.ConnectServer("MyMachine", "root/MicrosoftIISv2") 
set nodeObj = providerObj.Get("IIsWebVirtualDir='W3SVC/1/Root'") 

' Method 2
set providerObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2") 
set nodeObj = providerObj.get("IIsWebVirtualDir='W3SVC/1/ROOT'") 

' Method 3
set nodeObj = GetObject("winmgmts://MyMachine/root/MicrosoftIISv2:IIsWebVirtualDir='W3SVC/1/ROOT'") 

1 Answer 1

4

This first depends upon whether the string refers to an object or a class.
For objects; you can cast the string to wmi.
For classes; you can cast the string to wmiclass.

[wmi] 'root\MicrosoftIISv2:IIsWebVirtualDir="W3SVC/1/ROOT"'
[wmiclass] 'root\MicrosoftIISv2:IIsWebVirtualDir'

Some method names in WMI might be changed from their wsh names, eg SpawnInstance_ is now CreateInstance and Put_ is just Put.

wmi is an alias for System.Management.ManagementObject.
wmiclass is an alias for System.Management.ManagementClass

See https://stackoverflow.com/questions/261237/creating-an-iis-6-0-application-pool-using-powershell/264404#264404 for an example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .