Managing an Application Pool status through PowerShell

Are you tired of having to start IIS Manager to check out an application pool? Lucky for you this can be managed from PowerShell. Even remotely if neccesary. Here’s a crash course to get you going in under 10 minutes.

I’ll give a brief description of four different cmdlets that allow you to change the status of a given application pool. I’ll keep this as short as possible. For more in-depth documentation you can always check the Technet documentation on these cmdlets.

Get-WebAppPoolState
So you want to check whether a application pool is actually running or currently stopped? That’s where the Get-WebAppPoolState cmdlet comes into play. Usage in this case is rather easy:

Get-WebAppPoolState -Name "tovernaar.nl"

Value
-----
Stopped

You can substitute “tovernaar.nl” with the name of the application pool you’re trying to check out. This cmdlet will give you the current status for the give application pool. When it’s stopped you know for sure something’s wrong.

Start-WebAppPool
Now, when a application pool is stopped the site is not working and will display a HTTP 503 – Service Unavailable error. To solve this issue is easy. Just start the application pool using the Start-WebAppPool cmdlet like this:

Start-WebAppPool -Name "tovernaar.nl"

This cmdlet shouldn’t give you feedback this way, so check the application pool status with the Get-WebAppPoolState we used earlier:

Get-WebAppPoolState -Name "tovernaar.nl"

Value
-----
Started

As you can see, the application pool is now up and running again. Yay :)

Restart-WebAppPool
Now, what happens if a site just keeps loading and loading while the application pool status is Started? Most likely, the pool has crashed and your server isn’t yet aware of that. We could ofcourse stop the pool and then restart it. Good for us, there is one cmdlet for that:

Restart-WebAppPool -Name "tovernaar.nl"

Again, this provides no feedback. But if you’d check out the site it should be up and running again.

Stop-WebAppPool
The last cmdlet I’ll mention here is the Stop-WebAppPool cmdlet. This will (surprise, surprise) stop the application pool. Usage is similar to the cmdlets we used earlier:

Stop-WebAppPool -Name "tovernaar.nl"
Get-WebAppPoolState -Name "tovernaar.nl"

Value
-----
Stopped

So if you ever feel the urge to stop the application pool of a website, that’s how you do it.