How to get Applications of IIS AppPools into array?

Question:

To see all pools, their status and their applications inside IIS:\AppPools\, I use following command in PowerShell:

The output of this command is sorted in 3 columns named “Name“, “State” and “Applications“; It will look like this example:

My attempts at this point is to store the output of the command above into a array for later processing; Therefore I wrote following code in PowerShell:
(I annotated every step for better understanding)

This works well – I’m able to get the values by this scheme $MY_ARRAY[0...9].Name or for the status via $MY_ARRAY[0...9].Status. But I’m getting empty values by fetching the “Applications” column: $MY_ARRAY[0...9].Apps is always empty.

So does anybody know how to get the values form the column “Applications”?

Answer:

The reason Applications is always empty is because this is not actually a property on the object being returned. This data is being created in the console output by an output formatter in the webadministration module.

You can take a look at the properties available if you pipe your app pool object to Get-Member. You’ll notice that Applications doesn’t exist as a member. If you grab the full type name from Get-Member

you can head on over to the webadministration module to take a closer look. Typically you’ll find this at C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration

Inside the module you’ll find a file called iisprovider.format.ps1xml that is handling the output formatting. If you pop that open and search for the type name you’ll find the code that’s running to produce the output you see in the Applications column. The table column isn’t named so you’ll just have to count to the third column to find it. It looks like this.

You could pipe the output from Get-ChildItem –Path IIS:\AppPools\ to Out-String like $appPoolText = Get-ChildItem –Path IIS:\AppPools\ | Out-String and then parse it but that seems like a lot of work. For my use I just converted the formatter code into a function I could use.

You could then technically use that with Select-Object to create an inline custom object with a calculated property that would look the way you want it to. Something like

Get-ChildItem IIS:\AppPools\ | select Name,State,@{n='Applications';e={GetAppsInPool -pn $_.Name}}

Source:

How to get Applications of IIS AppPools into array? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply