26 Sep 2010

A few days ago, a colleague and I were looking for a way to recycle Application Pools in a PowerShell script.

Turned out that we couldn’t find any “native” way of doing this, but it is still possible to do it using the Microsoft.Web.Administration.ServerManager class:

function RecycleAppPools()
        $serv = new-object Microsoft.Web.Administration.ServerManager
        $serv.ApplicationPools | % { $_.Recycle() }

Not much, but still pretty useful. However, this will recycle all the Application Pools on the IIS server. In our case, we were only interested in recycling the Sharepoint related pools.

A simple Where did the trick:

$serv.ApplicationPools | ? { $_.Name -like "SharePoint*" } | % { $_.Recycle() }

blog comments powered by Disqus