I want to disable the idle timeout (Set it to Zero) of an application pool and I want to perform this at setup time, is it possible to perform this action from C# or PowerShell?
If you are using PowerShell 2 or later, you should have access to Set-ItemProperty. You'll also want to load the WebAdministration module.
You can then do (example taken from here)
Set-ItemProperty ("IIS:\AppPools\$name") -Name processModel.idleTimeout -value ( [TimeSpan]::FromMinutes(0))
and verify that the value was changed with
Get-ItemProperty ("IIS:\AppPools\$name") -Name processModel.idleTimeout.value
Get Application Pool Configuration (For Reference)
$appPoolName = 'MyAppPoolName'
$appPoolPath = '/system.applicationHost/applicationPools/Add[@name="' + $appPoolName + '"]//.'
Get-WebConfiguration $appPoolPath -PSPATH iis:
Set Application Pool Idle Timeout
$appPoolName = 'MyAppPoolName'
$appPoolPath = '/system.applicationHost/applicationPools/Add[@name="' + $appPoolName + '"]/processModel'
Set-WebConfigurationProperty $appPoolPath -Name idleTimeout -value ([TimeSpan]::FromMinutes(0)) -PSPATH iis:
When using powershell use the following:
$appPoolName = "xxxAppPool"
&"$env:windir\system32\inetsrv\appcmd" set APPPOOL $appPoolName /processModel.idleTimeout:0.00:00:00
I use the following function to generically grab an app pool object:
$query = "Select * From IIsApplicationPoolSetting WHERE WAMUserName LIKE '%$uServer'"
$query
$pools = Get-WmiObject -Authentication 6 -ComputerName $server -Query $query -Namespace 'root/microsoftiisv2'
if ($pools)
{
foreach ($pool in $pools)
{
Write-Host(" WAM Pool: " + $pool.Name + ", " + $pool.WAMUserName + " (" + $pool.WAMUserPass + ")")
}
}
And from an unrelated piece of code, here's where I place a site in a new App Pool. It's just an example how to use Set-WMIInstance.
if ($site.AppPoolID -ne $poolID)
{
# Write-Host("Updating $($site.Name) from $($site.AppPoolID) to $($poolID)")
$wmiArgs = @{"AppPoolID"=$poolID}
[void](Set-WMIInstance -InputObject $site -Arguments $wmiArgs)
} else {
# Write-Host("No update needed")
}
Use Get-Member to learn what properties your $pool has, then use Set-WMIInstance to modify them.
This is the script that i decided to use:
$myApplicationPool = Get-WmiObject -Class IISApplicationPoolSetting -Namespace "root\microsoftiisv2" | Where-Object {$_.Name -eq 'W3SVC/APPPOOLS/DefaultAppPool'}
$myApplicationPool.IdleTimeout=0
$myApplicationPool.Put()
If someone else has a better approach for this please let me know.
Hope this help someone
Regards.
%windir%\system32\inetsrv\appcmd set config -section:applicationPools
-applicationPoolDefaults.processModel.idleTimeout:00:00:00