Powershell: IIS Application Pool Killer

Every now and then IIS application pools lock up and needs to be killed. You can add the field PID in Task Manager and then use cmd tools to find which one of the IIS Worker Process is the right one and kill it. I created a simple script that lists all the IIS Application Pools by name, select the one you need to kill and the script kills it. The script is available on my Github and is named IISAppPoolKiller.ps1. Please comment below what you have been using this for!

Short break down of the script it self. First we load the modules needed.

Import-Module ServerManager
Add-WindowsFeature Web-Scripting-Tools
Import-Module WebAdministration

Then we list all the application pools and pipe that to a gridview. When you select one in the gridview we pipe that to a variable.

dir IIS:AppPools | Out-GridView -Title ‘Select apppool to restart’ -PassThru | Set-Variable -Name selectedAppPool

With the selected application pool we loop all the worker processes running and kill them.

foreach($worker in $selectedAppPool.workerProcesses.Collection)
Stop-Process $worker.processId

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: