![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | Re: Problems invoking IIS WMI method CreateNewSite Anyone have any idea? Thanks, Roy |
My System Specs![]() |
![]() |
| 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 | |||