Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keyan1603/8223efd50145ef77ca6273ba6a4d07b9 to your computer and use it in GitHub Desktop.
Save keyan1603/8223efd50145ef77ca6273ba6a4d07b9 to your computer and use it in GitHub Desktop.
Set multiple App pool recycles
# Define the app pool name
$appPoolName = "DefaultAppPool"
# Clear existing schedule
Clear-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$appPoolName']/recycling/periodicRestart/schedule"
# Add recycling times directly using WebConfiguration
Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST" `
-filter "system.applicationHost/applicationPools/add[@name='$appPoolName']/recycling/periodicRestart/schedule" `
-name "." -value @{ value = "02:00:00" }
Add-WebConfigurationProperty -pspath "MACHINE/WEBROOT/APPHOST" `
-filter "system.applicationHost/applicationPools/add[@name='$appPoolName']/recycling/periodicRestart/schedule" `
-name "." -value @{ value = "14:00:00" }
Write-Host "Recycle times added for $appPoolName."
Import-Module WebAdministration
# Define the app pool name
$appPoolName = "DefaultAppPool"
# Navigate to the application pool recycling schedule
$recycleTimesPath = "IIS:\AppPools\$appPoolName\recycling\periodicRestart\schedule"
# Clear existing schedule
Clear-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$appPoolName']/recycling/periodicRestart/schedule"
# Add new recycle times
Add-WebConfigurationProperty -pspath $recycleTimesPath -filter "." -name "." -value @{ value = "02:00:00" }
Add-WebConfigurationProperty -pspath $recycleTimesPath -filter "." -name "." -value @{ value = "14:00:00" }
Write-Host "Recycle times set!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment