Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List webapplications in IIS with powershell

The first sorry for my english, but I need your help with powershell scripting. I must config IIS server with powershell script and I have problem with "add application". I need to check whether webapplication exist in site. I want choose all webapplication in site "testsite2"

$webapplication=Get-WebApplication | Where-Object {$_. applicationpool -eq "testsite2"} | select -expand Name;

But I have problem that command is ending with error

select : Property "Name" cannot be found.At line:1 char:75 Get-WebApplication | Where-Object {$_. applicationpool -eq "testsite2"} | select ... CategoryInfo : InvalidArgument: (Microsoft.IIs.P...gurationElement:PSObject) [Select-Object], PSArgumentException FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

I don´t understand. What have I do when I want choose value from column "Name"?

I get same result

Get-ChildItem –Path IIS:\AppPools\ | Where-Object {$_. Name -eq "testsite2"} | select -ExpandProperty applications 

result:

select : Property "applications" cannot be found. At line:1 char:80 Get-ChildItem –Path IIS:\AppPools\ | Where-Object {$_. Name -eq "testsite2"} | s ... CategoryInfo : InvalidArgument: (Microsoft.IIs.P...gurationElement:PSObject) [Select-Object], PSArgumentException FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand

like image 450
spirit123 Avatar asked Oct 28 '25 14:10

spirit123


1 Answers

The WebAdministration module can be a bit deceiving in that it uses custom formatting data to show stuff like Name with Format-Table (even though the underlying objects have no Name property).

To get the equivalent Name value, take the Path property and trim /:

$WebAppNames = Get-WebApplication |Select @{Name='Name';Expression={$_.Path.Trim('/')}} |Select -Expand Name

The above is exactly what the formatting subsystem in PowerShell does to calculate the Name value.


You can explore the actual properties an object has with the Get-Member cmdlet:

Get-WebApplication |Get-Member

This will also show you the type name, which you can use to explore any additional Type- or Format-Data that might apply:

Get-TypeData -TypeName 'Microsoft.IIS.PowerShell.Framework.ConfigurationElement#site#application'
Get-FormatData -TypeName 'Microsoft.IIS.PowerShell.Framework.ConfigurationElement#site#application'
like image 161
Mathias R. Jessen Avatar answered Oct 30 '25 07:10

Mathias R. Jessen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!