Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeroenmaes/c3dd9cd554bd7e14e78ed6da0b9268fc to your computer and use it in GitHub Desktop.
Save jeroenmaes/c3dd9cd554bd7e14e78ed6da0b9268fc to your computer and use it in GitHub Desktop.
#https://www.saotn.org/iis-application-pool-recycle-on-specific-times-not-regular-time-interval/
Import-Module WebAdministration
$appPools = Get-ChildItem IIS:\apppools | where {$_.Name -match "APP1|APP2"}
$timeDiff = 0
$appPools | ForEach-Object {
$pool = $("IIS:\AppPools\") + ($_.Name)
#Disable Periodic Recycle
set-ItemProperty $pool -Name Recycling.periodicRestart.time -Value 0.00:00:00
#Set Fixed Interval Recycle
$time = (get-date 01:00:00).AddMinutes($timeDiff).ToString("HH:mm:ss")
clear-ItemProperty $pool -Name Recycling.periodicRestart.schedule
set-ItemProperty $pool -Name Recycling.periodicRestart.schedule -Value @{value=$time}
#Print
Write-Host $pool - $time
#Increment interval
$timeDiff+=5
#Use sleep because the change of the setting triggers a recycle...
Start-Sleep -s 30
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment