I am working on building scripts to set my startMode and idleTimeoutAction from octopus. My script is changing the startMode correctly, but I keep getting errors with the idleTimeoutAction. Can someone help me?
Here is the error i'm getting:
Executing script on 'APPSWDEV01' Setting LeadsAPI property startMode to AlwaysRunning Old value AlwaysRunning New value AlwaysRunning Done
Setting LeadsAPI property idleTimeoutAction to Suspend System.ArgumentException: Property ("idleTimeoutAction") is not found on \APPSWDEV01\AppPools\LeadsAPI. Parameter name: providerSpecificPickList at Microsoft.IIs.PowerShell.Provider.ConfigurationProvider.GetProperty(String path, Collection`1 providerSpecificPickList) There was a problem setting property
# Running outside octopus
param(
[string]$APIName,
[switch]$whatIf
)
$ErrorActionPreference = "Stop"
function Get-Param($Name, [switch]$Required, $Default) {
$result = $null
if ($OctopusParameters -ne $null) {
$result = $OctopusParameters[$Name]
}
if ($result -eq $null) {
$variable = Get-Variable $Name -EA SilentlyContinue
if ($variable -ne $null) {
$result = $variable.Value
}
}
if ($result -eq $null -or $result -eq "") {
if ($Required) {
throw "Missing parameter value $Name"
} else {
$result = $Default
}
}
return $result
}
& {
param(
[string]$APIName
)
if (![string]::IsNullOrEmpty($APIName))
{
Write-Host "Setting $APIName property startMode to AlwaysRunning"
try {
Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue
Import-Module WebAdministration -ErrorAction SilentlyContinue
$oldValue = Get-ItemProperty "IIS:\AppPools\$APIName" -Name "startMode"
$oldValueString = ""
if ($oldValue.GetType() -eq [Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute])
{
$oldValueString = ($oldValue | Select-Object -ExpandProperty "Value");
}
else
{
$oldValueString = $oldValue
}
Write-Host "Old value $oldValueString"
Set-ItemProperty "IIS:\AppPools\$APIName" -Name "startMode" -Value "AlwaysRunning"
Write-Host "New value AlwaysRunning"
Write-Host "Done"
} catch {
Write-Host $_.Exception|format-list -force
Write-Host "There was a problem setting property"
}
Write-Host "Setting $APIName property idleTimeoutAction to Suspend"
try {
Add-PSSnapin WebAdministration -ErrorAction SilentlyContinue
Import-Module WebAdministration -ErrorAction SilentlyContinue
$oldValue = Get-ItemProperty "IIS:\AppPools\$APIName" -Name "idleTimeoutAction"
$oldValueString = ""
if ($oldValue.GetType() -eq [Microsoft.IIs.PowerShell.Framework.ConfigurationAttribute])
{
$oldValueString = ($oldValue | Select-Object -ExpandProperty "Value");
}
else
{
$oldValueString = $oldValue
}
Write-Host "Old value $oldValueString"
Set-ItemProperty "IIS:\AppPools\$APIName" -Name "idleTimeoutAction" -Value "Suspend"
Write-Host "New value Suspend"
Write-Host "Done"
} catch {
Write-Host $_.Exception|format-list -force
Write-Host "There was a problem setting property"
}
}
} `
(Get-Param 'APIName' -Required)
I had a look at the file C:\Windows\System32\inetsrv\config\applicationHost.config
which contains app pool settings. When an idleTimeoutAction
is manually configured on an application pool, the result is an entry like:
<add name="MyAppPool" managedRuntimeVersion="v4.0">
<processModel idleTimeoutAction="Suspend" />
</add>
From PowerShell you can access the idleTimeoutAction
property via the command:
Get-ItemProperty "IIS:\AppPools\MyAppPool" -Name processModel.idleTimeoutAction
Likewise, you can set the idleTimeoutAction
property via:
Set-ItemProperty "IIS:\AppPools\MyAppPool" -Name processModel.idleTimeoutAction -Value "Suspend"
Hope this helps.