Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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'") 
share|improve this question
add comment

1 Answer

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 http://stackoverflow.com/questions/261237/creating-an-iis-6-0-application-pool-using-powershell/264404#264404 for an example.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.