![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Creating an IIS7 application with PowerShell I seem to be stuck trying to create a new IIS application using WMI and PowerShell. Based on code generated from WMIExplorer, I created the following function: function make-webapplication ($AppPath, $Directory, $SiteName) { $Computer = "." $Class = "Application" $Method = "Create" $MC = [WmiClass]"\\$Computer\ROOT\WebAdministration:$Class" $InParams = $mc.psbase.GetMethodParameters($Method) $InParams.ApplicationPath = $AppPath $InParams.PhysicalPath = $Directory $InParams.SiteName = $SiteName "Calling Application. : Create with Parameters :" $inparams.PSBase.properties | select name,Value | format-Table $R = $mc.PSBase.InvokeMethod($Method, $inParams, $Null) "Result :" $R | Format-list } However, whenever I run the function I get an error on the InvokeMethod call with a parameter error. |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Creating an IIS7 application with PowerShell Joe Brinkman wrote: Quote: > I seem to be stuck trying to create a new IIS application using WMI and > PowerShell. Based on code generated from WMIExplorer, I created the > following function: > > function make-webapplication ($AppPath, $Directory, $SiteName) { > $Computer = "." > $Class = "Application" > $Method = "Create" > $MC = [WmiClass]"\\$Computer\ROOT\WebAdministration:$Class" > $InParams = $mc.psbase.GetMethodParameters($Method) > $InParams.ApplicationPath = $AppPath > $InParams.PhysicalPath = $Directory > $InParams.SiteName = $SiteName > "Calling Application. : Create with Parameters :" > $inparams.PSBase.properties | select name,Value | format-Table > $R = $mc.PSBase.InvokeMethod($Method, $inParams, $Null) > "Result :" > $R | Format-list > } > > However, whenever I run the function I get an error on the InvokeMethod > call with a parameter error. > > to a function, and wrote the commands line-by-line. I started off with: $AppPath="/newapp" $Directory="C:\test" $SiteName="Default Web Site" $Computer="." So try it without putting everything into a function just to see. Perhaps something is happening to the args once passed in, so make sure to echo them to the screen. (Great VBScript examples: http://www.iis.net/articles/onepagea...n-Pools-on-IIS) Marco -- ---------------- PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Creating an IIS7 application with PowerShell Marco, I tried it from the command line as well when I first posted and I recieved exactly the same error. I am running on Vista so IIS7 is slightly different. Since the original code was generated by WMIExplorer I assumed that the code is probably correct. I am wondering if there may be some IIS setting or configuration that is not correct. I have tried running as both an admin and non-admin and I get the same error. Quote: > I tried on beta 3, and it worked fine. I didn't pass anything as args > to a function, and wrote the commands line-by-line. I started off > with: > > $AppPath="/newapp" > $Directory="C:\test" > $SiteName="Default Web Site" > $Computer="." > So try it without putting everything into a function just to see. > Perhaps something is happening to the args once passed in, so make > sure to echo them to the screen. > > (Great VBScript examples: > http://www.iis.net/articles/onepagea...-IIS7-Administ > ration-Tools/Scripting-IIS7/Managing-Applications-and-Application-Pool > s-on-IIS) > Marco > > Blog: > http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Creating an IIS7 application with PowerShell Joe Brinkman wrote: Quote: > Marco, > > I tried it from the command line as well when I first posted and I > recieved exactly the same error. I am running on Vista so IIS7 is > slightly different. Since the original code was generated by WMIExplorer > I assumed that the code is probably correct. I am wondering if there > may be some IIS setting or configuration that is not correct. I have > tried running as both an admin and non-admin and I get the same error. Check this guy's super-duper IIS blog for code samples: http://weblogs.asp.net/steveschofield/default.aspx Marco -- ---------------- PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Creating an IIS7 application with PowerShell Joe Brinkman wrote: Quote: > Marco, > > I tried it from the command line as well when I first posted and I > recieved exactly the same error. I am running on Vista so IIS7 is > slightly different. Since the original code was generated by WMIExplorer > I assumed that the code is probably correct. I am wondering if there > may be some IIS setting or configuration that is not correct. I have > tried running as both an admin and non-admin and I get the same error. app was created successfully. I had just added IIS (for this test), and the web scripting component to this VM, so IIS is set to all the defaults. I ran the code against the default web site. Have you tried this on a new site with the default settings? I don't have SP1 installed, do you? Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Creating an IIS7 application with PowerShell OK. I am an idiot. I guess sometimes you really should look at the documentation closely. I was passing in a sitename thinking that it described the web application rather than the site where I was adding the application. My original function works just fine. Although on a positive note, I now have a better understanding of using WMI with Powershell (although the WMI part of that eqation still presents plenty of mystery). Thanks for all the help. Joe Brinkman ---------------------------------------------------------- DotNetNuke Corp. ASP.Net MVP www.dotnetnuke.com ---------------------------------------------------------- Quote: > Joe Brinkman wrote: > Quote: >> Marco, >> >> I tried it from the command line as well when I first posted and I >> recieved exactly the same error. I am running on Vista so IIS7 is >> slightly different. Since the original code was generated by >> WMIExplorer I assumed that the code is probably correct. I am >> wondering if there may be some IIS setting or configuration that is >> not correct. I have tried running as both an admin and non-admin and >> I get the same error. >> > the app was created successfully. > > I had just added IIS (for this test), and the web scripting component > to this VM, so IIS is set to all the defaults. I ran the code against > the default web site. > > Have you tried this on a new site with the default settings? I don't > have SP1 installed, do you? > > Marco > > PowerGadgets MVP > http://www.powergadgets.com/mvp > Blog: > http://marcoshaw.blogspot.com |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| re: Creating an Installer for a Service and an Application | .NET General | |||
| Help to get PowerShell to add/edit/delete IIS Manager Users IIS7/2 | PowerShell | |||
| Problem creating Application in IIS 6 | PowerShell | |||
| Problem creating Application in IIS 6.0 | PowerShell | |||
| What no IIS7 PowerShell Examples (yet)? | PowerShell | |||