How do I recycle an IIS App pool with Powershell?
- by Ralph Willgoss
Reference implementation of a Powershell script to recycle app pools, in response to Rick's post:http://www.west-wind.com/weblog/posts/2012/Oct/02/A-tiny-Utility-to-recycle-an-IIS-Application-Pool# File: RecycleAppPool.ps1# Author: Ralph Willgoss# Date: 2nd Oct 2012# Reference:# http://stackoverflow.com/questions/198623/how-do-i-recycle-an-iis-apppool-with-powershell# # Alternative is to create a Process and run the inbuilt vbs:# C:\WINDOWS\system32\iisapp.vbs => "IIsApp /a DefaultAppPool /r"# # Windows 2003 & II6 C:\WINDOWS\system32>cscript.exe iisapp.vbs /a StaticDataAppPool /r# Windows 2008 IIS7 [tbd]# =============================================================================# Iniatialise=============================================================================param ( )=============================================================================# Main=============================================================================Write-OutPut ""Write-OutPut "Starting Recycling App Pool"Write-OutPut ""$appPoolName = "StaticDataAppPool" #$args[0]$appPool = Get-WmiObject -namespace "root\MicrosoftIISv2" -class "IIsApplicationPool" | Where-Object { $_.Name -eq "W3SVC/APPPOOLS/$appPoolName" } $appPool.Recycle()Write-OutPut ""Write-OutPut "Finished Recycling App Pool"Write-OutPut ""