Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Creating an IIS7 application with PowerShell

Closed Thread
 
Thread Tools Display Modes
Old 10-01-2007   #1 (permalink)
Joe Brinkman
Guest


 

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.


Old 10-02-2007   #2 (permalink)
Marco Shaw
Guest


 

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
Old 10-02-2007   #3 (permalink)
Joe Brinkman
Guest


 

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

Old 10-02-2007   #4 (permalink)
Marco Shaw
Guest


 

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


 

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
Old 10-03-2007   #6 (permalink)
Joe Brinkman
Guest


 

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

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem creating Application in IIS 6 bsbirdwell PowerShell 1 02-20-2008 03:43 PM
Problem creating Application in IIS 6.0 bsbirdwell PowerShell 0 02-20-2008 10:20 AM
What no IIS7 PowerShell Examples (yet)? Flowering Weeds PowerShell 4 01-08-2008 04:55 PM
creating a powershell webservice Justin Rich PowerShell 2 09-06-2007 10:37 AM
Creating WC in PowerShell Brandon Shell PowerShell 3 08-16-2006 07:11 AM








Vistax64.com 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 2005-2008

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 47 48 49 50