By default, an IIS application pool (or “AppPool”) recycles on a regular time interval of 1740 minutes, or 29 hours. One reason for this time interval is that application pools don’t recycle at the same moment every day (every day at 07.00 for example). However, sometimes you want to change this regular time interval to specific times. And when you try to configure this in IIS Manager, it gives you an error. Luckily, AppCmd and PowerShell come to the rescue!

IIS Application Pool recycling defaults

Recycling means the worker process that handles requests for an application pool is terminated and a new worker process is started.

Why is IIS’ default application pool recycling set to 1740 minutes? One reason for this time interval is that application pools don’t recycle at the same moment every day, and 29 hours for the simple reason that it’s the smallest prime number over 24. A staggered and non-repeating pattern that doesn’t occur more frequently than once per day, “you don’t get a resonate pattern” (Source: Scott Forsyth’s Blog).

Imagine your IIS application pool (AppPools) are configured to recycle on a regular time interval of 1740 minutes, and you want to change this setting through Internet Information Services (IIS) Manager to a time interval. You either browse to an application pool and its Advanced Settings, or you try to set Application Pool Defaults.

This may interest you:   25 New SQLServer PowerShell cmdlets

When you set the Regular Time Interval (minutes) to 0, an error message pops up:

AppPool IdleTime-out property error
AppPool IdleTime-out property error

The ‘Idle Time-out (minutes)’ property of the application pool’s process model must be less than the Regular Time Interval (minutes)’ property of the application pool’s period restart.

Setting the AppPool Idle Time-out property to zero (0) -because you want to set the Regular Time Interval to 0- may result in unwanted AppPool and website behavior… This is a known bug in the IIS Manager GUI.

Appcmd to configure application pool recycle on Specific Times and set Regular Time Interval to 0

Configure a periodicRestart

Fortunately you can use AppCmd to configure these Regular Time Interval and Specific Times Application Pool Defaults settings. First you have to set the Regular Time Interval to 0:

AppCmd set config
 -section:system.applicationHost/applicationPools
 /applicationPoolDefaults.recycling.periodicRestart.time:"00:00:00"
 /commit:apphost

Next, you’ll configure a Periodic Restart Schedule (4 A.M):

AppCmd set config
 -section:system.applicationHost/applicationPools
 "/+applicationPoolDefaults.recycling.periodicRestart.schedule.[@0,value='04:00:00']"
 /commit:apphost

The @0 numeric index is used so more than one periodic restart schedules can be created (not sure this is necessary). This makes all application pools to recycle at 4 A.M in the morning, suppose you would want this.

In PowerShell, set application pool Specific Times TimeSpan value

If you want to use a more PowerShell solution to set an application pool to recycle on a specific time (in stead of a regular interval), you can use the following PS snippets:

Set-WebConfiguration `
  /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart `
  -value "0"

And then you add a specific time for the application pool to recycle on (note the add-, not set-):

Add-WebConfiguration ` 
  /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule `
  -value (New-TimeSpan -h 4 -m 00)

Verify your newly made settings:

Get-WebConfiguration `
  /system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule/add ` 
  | select value

Get the Specific Times recycle value of a specific Applicaton Pool using PowerShell’s Get-ItemProperty

If you have set one or more specific times recycle values for an application pool, use the following PowerShell command to get the values:

(Get-ItemProperty ('IIS:\AppPools\example.org') -Name Recycling.periodicRestart.schedule.collection) | select value

The output is for example set to every 6 hours on the hour, starting at midnight:

value
-----
00:00:00
06:00:00
12:00:00
18:00:00

Get recycling.periodicRestart.schedule using appcmd:

appcmd.exe list apppool example.com /config

The appcmd command above will list the current application pool ‘example.com’ configuration, including its scheduled periodicRestart. Substitute /config with /text:* for all configuration settings for that pool.

This may interest you:   Disk Cleanup in Windows Server

And the IIS Manager GUI?

After setting the regular time interval to 0, you may use the IIS Manager GUI to configure Application Pool Defaults and a Periodic Restart schedule.

Reset Application Pool recycling Defaults back to periodicRestart

If you want to reset your application pool recycling defaults back to periodicRestart (Regular Time Interval), you can do so with the following appcmd command:

# Set applicationPoolDefaults.recycling.periodicRestart.time
# to 29 hours, 1 minute, or 1741 minutes
AppCmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"29:01:00" /commit:apphost
# Set applicationPoolDefaults.recycling.periodicRestart.time
# to 29 hours, or 1740 minutes
AppCmd set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.recycling.periodicRestart.time:"29:00:00" /commit:apphost

Note: If the Regular Time Interval default is set to 41760 minutes / 29 days, you must reset this to a non-default value. For example 1741. When that’s saved to applicationHost.config, you can reset it back to it’s original regular time interval of 1740 minutes.


Is this post worth a small donation to you? Did it help you solve a problem? Or just want to say thanks?

If you found this post interesting, or it helped you solve a problem , why not buy me a coffee?

A small donation of only $5 helps out a lot in the development, research and hosting of this blog.

If I’ve helped you out and you want to thank me, why not buy me a coffee?

Thank you for your support.