Question

Here is what doesn't work

>dir IIS:\AppPools\ | % { dir IIS:\AppPools\$_.Name\WorkerProcesses }

More Info

I want to use Powershell to get the PID of each Application pool. I understand that I could use WMI to get the information like the command below, but I'm trying to use Powershell's WebAdministration module.

WMI Approach (working sample)

Get-WmiObject -NameSpace 'root\WebAdministration' -class 'WorkerProcess' -ComputerName 'host' | select AppPoolName, ProcessId | ft -a

AppPoolName                   ProcessId
-----------                   ---------
MSExchangePowerShellAppPool        5432
MSExchangeServicesAppPool          3604
MSExchangeOWAAppPool               7056
MSExchangeAutodiscoverAppPool      6012
DefaultAppPool                     3288
MSExchangeSyncAppPool              2944

Powershell Approach (not working sample.. help!)

How do I combine the outputs of the two commands (perhaps as a single line) to also give me the PID for each app pool?

[PS] C:\Windows\system32>import-module WebAdministration
[PS] C:\Windows\system32>dir IIS:\AppPools

Name                     State        Applications
----                     -----        ------------
Classic .NET AppPool     Started
DefaultAppPool           Started      Default Web Site
                                      /Rpc
                                      /RpcWithCert
                                      /ArchiveProxy
MSExchangeAutodiscoverAp Started      /Autodiscover
pPool                                 /Autodiscover/bin
                                      /Autodiscover/help
MSExchangeECPAppPool     Started      /ecp
MSExchangeOWAAppPool     Started      /owa
                                      /owa/oma
                                      /ArchiveProxyOwa
MSExchangeOWACalendarApp Started      /owa/Calendar
Pool
MSExchangePowerShellAppP Started      /PowerShell
ool
MSExchangeServicesAppPoo Started      /EWS
l                                     /EWS/bin
MSExchangeSyncAppPool    Stopped      /Microsoft-Server-ActiveSync

The second query I want to combine is this:

[PS] C:\Windows\system32>dir IIS:\AppPools\DefaultAppPool\WorkerProcesses  | fl


processId : 3904
Handles   : 89516
state     : Running
StartTime : 2/19/2013 10:34:57 PM
Was it helpful?

Solution

you just have to expand the property you need :

dir IIS:\AppPools\ |select -expand name| % { dir IIS:\AppPools\$_\WorkerProcesses } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top