Thread: WMI in IIS 6.0
View Single Post
Old 10-02-2007   #1 (permalink)
NJC


 
 

WMI in IIS 6.0

Hello,

I am trying to create a new website on IIS 6.0. I have successfully
completed this task using VBScript, but I’m struggling converting the code
into Powershell, because I am newbie to WMI and fairly new to Powershell. My
VBScript code is as follows:

set locatorObj = CreateObject("Wbemscripting.SWbemLocator")
set providerObj = locatorObj.ConnectServer("localhost",
"root/MicrosoftIISv2")
set serviceObj = providerObj.Get("IIsWebService='W3SVC'")

Bindings = Array(0)
Set Bindings(0) = providerObj.get("ServerBinding").SpawnInstance_()
Bindings(0).IP = ""
Bindings(0).Port = "8383"
Bindings(0).Hostname = ""

Dim strSiteObjPath
strSiteObjPath = serviceObj.CreateNewSite("MyNewSite", Bindings,
"C:\Inetpub\Wwwroot")


I have tried to convert the variable declaration and object instantiation to
the following:
$locatorObj = new-object -com WbemScripting.SWbemLocator
$providerObj = $locatorObj.ConnectServer("localhost","root/MicrosoftIISv2")
$serviceObj = $providerObj.Get("IIsWebService='W3SVC'")

This conversion does not provide a build error but when I try to invoke the
CreateNewSite() on the $serviceObj variable I get an error explaining that
$serviceObj does not contain a function or method CreateNewSite(). This is
strange because I reckon it should, considering WMI is supported by
Powershell.

So I’m guessing there is a problem passing “root/MicrosoftIIsv2” to
$locatorObj.ConnectServer but I’m not entirely sure what to pass as an
alternative.

If anyone can explain where I’m going wrong, or provide some direction or
even convert the VBScript code snippet for me I’d be very much
appreciative.

Thanks in advance,

My System SpecsSystem Spec