Powershell One Liner to do a Quick IIS App Pool Recycle
As I mentioned on a previous post, doing an IIS Reset is the worse thing you can do to an IIS Environment. 99% of the time you just need to tear down the AppDomain and load a new one. Performing an IIS Reset does that and also shuts down your HTTP Server, causing clients to receive TCP connection errors. Here’s a quick Powershell one liner to recycle all the Application Pools in IIS7 or IIS8. The command pipes the current list of App Pools in XML format into a recycle command. This is good for code deployment scripts or if you need a scheduled customized restart script.
Of course, as with any IT technique there’s 100 other ways to do it. But this has been one of my favorites. Read up on AppCmd for other ideas, or the WebAdministration Powershell Module.
Update 8/13
JJDurant posted a good question about how to selectively restart Application Pools. I guess there’s two ways to handle this, you could prompt the user if they want to restart each app pool. Or you could make the script accept the app pool name and then pass it to the /AppPool.Name paramenter. I like the second way better myself, but if you didn’t know all the pool names the first way could be useful.
Update 8/14
I added a third script that lists all the Application Pools and lets the user select the Pool to restart.