Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter

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")
     }
   }

}

 
 
 

 

Posted on Thursday, December 16, 2010 3:59 PM Programming , PowerShell | Back to top


Comments on this post: PowerShell – Recycle All IIS App Pools

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net