List webapplications in IIS with powershell

Question:

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”

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

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

Answer:

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 /:

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:


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

Source:

List webapplications in IIS with powershell by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply