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 - Creating an IIS7 application with PowerShell

Reply
 
Old 10-01-2007   #1 (permalink)
Joe Brinkman


 
 

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 SpecsSystem Spec
Old 10-02-2007   #2 (permalink)
Marco Shaw


 
 

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.
>
>
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...n-Pools-on-IIS)

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 10-02-2007   #3 (permalink)
Joe Brinkman


 
 

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 SpecsSystem Spec
Old 10-02-2007   #4 (permalink)
Marco Shaw


 
 

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.
I've got Vista Biz, but can't check right now.

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 SpecsSystem Spec
Old 10-02-2007   #5 (permalink)
Marco Shaw [MVP]


 
 

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.
OK, I tried this my Vista Business VM, and I didn't get an error and 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

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 10-03-2007   #6 (permalink)
Joe Brinkman


 
 

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.
>>
> OK, I tried this my Vista Business VM, and I didn't get an error and
> 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 SpecsSystem Spec
Reply

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


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