PowerShell – Recycle All IIS App Pools
Posted
by Lance Robinson
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Lance Robinson
Published on Thu, 16 Dec 2010 20:59:17 GMT
Indexed on
2010/12/18
17:15 UTC
Read the original article
Hit count: 370
With a little help from Shay Levy’s post on Stack Overflow and the MSDN documentation, I added this handy function to my profile to automatically recycle all IIS app pools.
function Recycle-AppPools { param( [string] $server = "3bhs001", [int] $mode = 1, # ManagedPipelineModes: 0 = integrated, 1 = classic )$iis = [adsi]"IIS://$server/W3SVC/AppPools"
$iis.psbase.children | %{
$pool = [adsi]($_.psbase.path);
if ($pool.AppPoolState -eq 2 -and $pool.ManagedPipelineMode -eq $mode) {
# AppPoolStates: 1 = starting, 2 = started, 3 = stopping, 4 = stopped
$pool.psbase.invoke("recycle")
}
}}
© Geeks with Blogs or respective owner