Blog Post

Reset of app pool in IIS using powershell

Friday, July 10, 2015 10:35 PM

I needed to reset IIS using PowerShell script
Lets define our script first as it it easy to update or automate

$site = "CpoDesign HomeSite"

No the script should be pretty agnostic and we are able to transfer it anywhere.
To use the IIS module we need to import it.
Import-Module WebAdministration
Lets use the powershell querying to retrieve app pool property from object associated with our site using
$pool = (Get-Item "IIS:\Sites\$site"| Select-Object applicationPool).applicationPool
Now the final command
Restart-WebAppPool $pool
Note: If you might experience issues it might be due to access rights, so make sure that the script is tested under right credentials 
For your convenience here is full script below or link here
Full script
# Set a name of sie we want to recycle the app pool for:
$site = "CpoDesign HomeSite"

# Import the IIS module:
Import-Module WebAdministration

# Find the item from IIS and from selected objects select the app pool property
$pool = (Get-Item "IIS:\Sites\$site"| Select-Object applicationPool).applicationPool

# Restart the application pool
Restart-WebAppPool $pool