in C#/Powershell - Is it possible to change the Idle TimeOut for an IIS Application Pool?

前端 未结 8 521
别那么骄傲
别那么骄傲 2021-02-05 08:29

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?

8条回答
  •  情书的邮戳
    2021-02-05 09:10

    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.

提交回复
热议问题