Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Problems invoking IIS WMI method CreateNewSite

Reply
 
Old 01-04-2007   #1 (permalink)
rtrmartin@gmail.com


 
 

Problems invoking IIS WMI method CreateNewSite

Hi

I've been struggling with a script that is intended to create a new web
site in IIS 6. I'm trying to use the IIS WMI method CreateNewSite, but
the script throws an error. I'm sure I must be doing something silly,
but I can't see what it is!

First the script:-

$strcomputer = "localhost"

$webserver =
([wmiclass]"root/MicrosoftIISv2:ServerBinding").CreateInstance()
$webserver.Hostname = $strcomputer

$website =
([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite("This is
a test Site Created by Script", $webserver, "c:\inetpub")

And the error:-

Method invocation failed because [System.Management.ManagementClass]
doesn't contain a method named 'CreateNewSite'.
At C:\Documents and Settings\Administrator\My
Documents\Scripts\iis.ps1:24 char:73
+ $website =
([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite( <<<<
"This is a test Site Created by Script
", $webserver, "c:\inetpub")

Anyone able to help?

Roy


My System SpecsSystem Spec
Old 01-04-2007   #2 (permalink)
/\/\o\/\/ [MVP]


 
 

RE: Problems invoking IIS WMI method CreateNewSite

you need to use PSbase since RC3:
for more info see this blogentry in my RC2 WMI series :

http://mow001.blogspot.com/2006/10/p...c2-series.html

as your working with IIS this part (3) about connection settings migh also
be handy :

http://mow001.blogspot.com/2006/10/p...rt-in-rc2.html

Greetings /\/\o\/\/

"rtrmartin@gmail.com" wrote:

> Hi
>
> I've been struggling with a script that is intended to create a new web
> site in IIS 6. I'm trying to use the IIS WMI method CreateNewSite, but
> the script throws an error. I'm sure I must be doing something silly,
> but I can't see what it is!
>
> First the script:-
>
> $strcomputer = "localhost"
>
> $webserver =
> ([wmiclass]"root/MicrosoftIISv2:ServerBinding").CreateInstance()
> $webserver.Hostname = $strcomputer
>
> $website =
> ([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite("This is
> a test Site Created by Script", $webserver, "c:\inetpub")
>
> And the error:-
>
> Method invocation failed because [System.Management.ManagementClass]
> doesn't contain a method named 'CreateNewSite'.
> At C:\Documents and Settings\Administrator\My
> Documents\Scripts\iis.ps1:24 char:73
> + $website =
> ([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite( <<<<
> "This is a test Site Created by Script
> ", $webserver, "c:\inetpub")
>
> Anyone able to help?
>
> Roy
>
>

My System SpecsSystem Spec
Old 01-04-2007   #3 (permalink)
Krishna Vutukuri[MSFT]


 
 

Re: Problems invoking IIS WMI method CreateNewSite

Hi Roy,

As per the documentation CreateNewSite() method is available on an
instance - WMI object (not WMI calls). So using [wmiclass] will not help in
creating a new site. Use an instance of IISWebservice like this:

PS C:\Documents and Settings\kriscv> $iis =
[wmi]'root/MicrosoftIISv2:IISWebService="W3SVC"'
PS C:\Documents and Settings\kriscv> $iis | gm createnewsite | fl


TypeName :
System.Management.ManagementObject#root\MicrosoftIISv2\IIsWebService
Name : CreateNewSite
MemberType : Method
Definition : System.Management.ManagementBaseObject
CreateNewSite(System.String ServerComment, System.Management.Manage
mentObject#ServerBinding[] ServerBindings, System.String
PathOfRootVirtualDir, System.Int32 ServerId)

Notice the use of [wmi] to refer to an instance of wmi class:
[wmi]'root/MicrosoftIISv2:IISWebService="W3SVC"'

--
Thanks
Krishna[MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

<rtrmartin@gmail.com> wrote in message
news:1167915243.507600.12100@s34g2000cwa.googlegroups.com...
> Hi
>
> I've been struggling with a script that is intended to create a new web
> site in IIS 6. I'm trying to use the IIS WMI method CreateNewSite, but
> the script throws an error. I'm sure I must be doing something silly,
> but I can't see what it is!
>
> First the script:-
>
> $strcomputer = "localhost"
>
> $webserver =
> ([wmiclass]"root/MicrosoftIISv2:ServerBinding").CreateInstance()
> $webserver.Hostname = $strcomputer
>
> $website =
> ([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite("This is
> a test Site Created by Script", $webserver, "c:\inetpub")
>
> And the error:-
>
> Method invocation failed because [System.Management.ManagementClass]
> doesn't contain a method named 'CreateNewSite'.
> At C:\Documents and Settings\Administrator\My
> Documents\Scripts\iis.ps1:24 char:73
> + $website =
> ([wmiclass]"root/MicrosoftIISv2:IISWebService").CreateNewSite( <<<<
> "This is a test Site Created by Script
> ", $webserver, "c:\inetpub")
>
> Anyone able to help?
>
> Roy
>



My System SpecsSystem Spec
Old 01-05-2007   #4 (permalink)
rtrmartin@gmail.com


 
 

Re: Problems invoking IIS WMI method CreateNewSite

Thanks Krishna amd Mow for your help, that's fixed my problem.

I do have a follow-up question...

Having created the site, I'm trying to use IIsWebVirtualDirSetting to
manipulate it's properties.

I've created the site and extracted the site's id from the returnvalue.
I've then used this to initiate a instance of IIsWebVirtualDirSetting,
and tried to manipulate a couple of values. The site creates ok, but
none of the values are changed.

$iis = [wmi]'root/MicrosoftIIsv2:IIswebService="W3SVC"'
$website = $iis.CreateNewSite($sitename, $webserver, $websitepath)
....
$siteid = $website.returnvalue
$a = $siteid.indexof("'")
$siteid = $siteid.substring($a+1,$siteid.length-$a-2)
Write-Host $siteid
$vdirobj =
[wmi]"root\MicrosoftIISv2:IIsWebVirtualDirSetting='$siteid/root'"
$vdirobj.AppFriendlyName = "Roy"
$vdirobj.AccessRead = $true
$vdirobj.put()

Any ideas?

Thanks again,

Roy

My System SpecsSystem Spec
Old 01-08-2007   #5 (permalink)
rtrmartin@gmail.com


 
 

Re: Problems invoking IIS WMI method CreateNewSite


Anyone have any idea?

Thanks,

Roy

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Method invocation failed because [System.String] doesn't contain a method PowerShell
Invoking PS script in RunOnce PowerShell
Invoking cmdlets from java PowerShell
Invoking PowerShell from WScript via COM PowerShell
Invoking Powershell from C# PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46