How to get IIS AppPool Worker Process ID

后端 未结 3 1635
情深已故
情深已故 2020-12-13 05:08

I have a PowerShell script that is run automatically when our monitoring service detects that a website is down. It is supposed to stop the AppPool (using Stop-WebAppP

相关标签:
3条回答
  • 2020-12-13 05:42

    (Adding answer from Roman's comment, since there maybe cache issues with stej's solution)

    Open Powershell as an Administrator on the web server, then run:

    gwmi -NS 'root\WebAdministration' -class 'WorkerProcess' | select AppPoolName,ProcessId 
    

    You should see something like:

    AppPoolName ProcessId
    ----------- ---------
    AppPool_1        8020
    AppPool_2        8568
    

    You can then use Task Manager to kill it or in Powershell use:

    Stop-Process -Id xxxx
    

    If you get Get-WmiObject : Could not get objects from namespace root/WebAdministration. Invalid namespace then you need to enable the IIS Management Scripts and Tools feature using:

    ipmo ServerManager
    Add-WindowsFeature Web-Scripting-Tools
    
    0 讨论(0)
  • 2020-12-13 05:45

    In Command Prompt on the server, I just do the following for a list of running AppPool PIDs so I can kill them with taskkill or Task Mgr:

    cd c:\windows\system32\inetsrv
    appcmd list wp
    

    taskkill /f /pid *PIDhere*
    
    0 讨论(0)
  • 2020-12-13 05:51

    In case that Process ID is really the id of process to kill, you can:

    $id = dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | Select-Object -expand processId
    Stop-Process -id $id
    

    or

    dir IIS:\AppPools\MyAppPool\WorkerProcesses\ | % { Stop-Process -id $_.processId }
    
    0 讨论(0)
提交回复
热议问题