IIS Application pool PID

Viewed 41523

is anyone familiar with a way to get the Application pool that is associated with a process ID ? I am using Win32_Process to query the W3WP services and return the PID now I am trying to get the app pool associated with it.

10 Answers

If you are just using command line to figure it out ad-hoc you can do this too:

The script is already placed in systemroot\system32 on Windows Server 2003 so simply go to your Command Prompt and type in iisapp.vbs (the .vbs is optional) and you'll have an instant list of all the App Pool information you've always wanted to know. You may need to type cscript iisapp.vbs if CScript isn't your default WSH script host.

Let's see an example of the output:

W3WP.exe PID: 1468 AppPoolId: AppPoolForSite1.com
W3WP.exe PID: 3056 AppPoolId: AppPoolForSite2.com
W3WP.exe PID: 1316 AppPoolId: AppPoolForSite3.com

Direct from the horse's mouth, Microsoft documents this.

ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;

Try working with this and it should get you what you need.

If you have multiple app pools and want to the know PID of each. You can run the powershell below which will iterate through all the app pools on the machine, query the PID, and displays the App Pool Name and PID in a nice table format.

import-module webadministration

$dirs = dir IIS:\AppPools\

foreach($dir in $dirs)
{
    Write-Output([pscustomobject]@{
        Name = $dir.Name
        PID = (dir IIS:\AppPools\$($dir.Name)\WorkerProcesses).ProcessId
    })
}
Related