Last active
September 5, 2024 19:03
-
-
Save keyan1603/8223efd50145ef77ca6273ba6a4d07b9 to your computer and use it in GitHub Desktop.
Set multiple App pool recycles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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