Powershell Script – Recycle Specific Application Pool

Powershell Script – Recycle Specific Application Pool
3 votes, 5.00 avg. rating (97% score)

Introduction

The following script will restart application pool of IIS based on user input. User will just select the number which application pool to restart. Very good on demand usage script

 
Import-Module WebAdministration -ErrorAction SilentlyContinue 
$pooltable = @{} 
$pools = gci iis:\apppools 
$i = 0  
Write-Host "Select Application Pool to Restart"
Write-Host ""  
foreach ($a in $pools )
{
$pool = $a.Name
$i += 1
$pooltable.Add($i, $pool)
Write-Host "$i > To restart app pool : $pool "
} 
Write-Host "" 
$answer = read-host "Enter # of Application Pool to Restart " 
if ($answer)
{     
	foreach ($h in $pooltable.GetEnumerator()) 
	{   
		$key = $h.Name
		$val = $h.Value  
			if ($key -eq $answer)
			{
			Write-Host "Restarting : $val"            
			Restart-WebAppPool $val         
			}  
	}
}   
Write-Host "Complete" -ForegroundColor Magenta 
Write-Host ""  

Save the script into a powershell script file and execute. Script will prompt user which application pool to restart. User can input the desired index number pointing to tha application pool

image

Conclusion

Hope this powerful script will help you to quickly recycle desired app pool.

March 17, 2015 В· Adi В· No Comments
Tags: , ,  В· Posted in: Powershell, Sharepoint 2010, SharePoint 2013

Leave a Reply

What is 4 + 13 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)