【问题标题】:Setting app pools to recycle at multiple specific times via powershell or appcmd does not display both times in GUI/IIS通过 powershell 或 appcmd 将应用程序池设置为在多个特定时间回收不会在 GUI/IIS 中显示两次
【发布时间】:2020-05-09 03:15:05
【问题描述】:

我正在尝试在 iis 8.5 中将应用程序池设置为一天内多次回收,我尝试使用 powershell 和 app 命令,并且在池中没有站点/应用程序的服务器上进行测试时,它似乎可以工作完美,但是当尝试在应用程序池中有站点的服务器上使用任何一种方法进行设置时,我看到了奇怪的行为,但是如果我查看应用程序池的回收设置,它似乎在 IIS 的 GUI 中有效显示指定的时间之一。 最初尝试使用的 Powershell 脚本是:

function Set-ApplicationPoolRecycleTimes {
    param (
        [string]$ApplicationPoolName,
        [string[]]$RestartTimes
    )
    Import-Module WebAdministration
    Write-Output "Updating recycle times for $ApplicationPoolName"
    # Delete all existing recycle times
    Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.schedule    
    Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.time
    foreach ($restartTime in $RestartTimes) {
        Write-Output "Adding recycle at $restartTime"
        # Set the application pool to restart at the time we want
        New-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.schedule -Value @{value=$restartTime}
        Set-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.time -Value "00:00:00"
    } # End foreach restarttime
} # End function Set-ApplicationPoolRecycleTimes
$apppoolname1 = "app pool's name"
$restartat = @("1:45", "18:45")
Set-ApplicationPoolRecycleTimes -ApplicationPoolName $apppoolname1 -RestartTimes $restartat

除非应用程序池中有站点,否则这似乎工作得很好。当站点存在时,它似乎可以工作,只是 gui 只显示设置的时间之一:

然而查询值显示的两次:

Import-Module WebAdministration
(Get-ItemProperty ('IIS:\AppPools\app pool name') -Name Recycling.periodicRestart.schedule.collection) | select value

value   
-----   
18:45:00
01:45:00

也尝试使用 appcmd 但发现相同的结果,在应用程序池中没有站点的服务器上完美运行,但是当针对具有站点的服务器运行时,在 gui 中丢失了一次,查询显示了两次。我已打开应用程序池回收的登录,以确认这两次都发生了,但我想知道我是否只是忽略了一些明显的事情。

appcmd 脚本:

CD C:\windows\System32\inetsrv
$V1 = "app pool name"
#clears any existing schedule
cmd.exe /c appcmd.exe set apppool /apppool.name: $V1 /-recycling.periodicRestart.schedule
#setting desired recycles 
cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='01:45:00']" /commit:apphost
cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='18:45:00']" /commit:apphost

【问题讨论】:

  • 对我来说(我在池中有一个站点),它查询并且这家伙显示了两个时间。话虽如此,我使用-Value $restartTime 而不是-Value @{value=$restartTime},因为后者给了我一个错误(无效的演员表)我担心我无法重现你的行为,但我再次只在我的工作站(Windows 10)上进行了测试,这样可能是问题的一部分...

标签: powershell windows-server-2012-r2 application-pool iis-8.5 appcmd


【解决方案1】:

我在包含站点或不包含站点的应用程序池中尝试了您的 PowerShell 脚本。在您发布的脚本正常工作的情况下。

您可以尝试使用以下脚本:

    function Set-ApplicationPoolRecycleTimes {

    param (
        [string]$ApplicationPoolName,
        [string[]]$RestartTimes
    )

    Import-Module WebAdministration

    Write-Output "Updating recycle times for $ApplicationPoolName"

    # Delete all existing recycle times
    Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.schedule

    foreach ($restartTime in $RestartTimes) {

        Write-Output "Adding recycle at $restartTime"
        # Set the application pool to restart at the time we want
        New-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.schedule -Value @{value=$restartTime}

    } # End foreach restarttime

} # End function Set-ApplicationPoolRecycleTimes
$apppoolname = "abcsite"
$restartat = @("05:55", "12:55", "17:00")

Set-ApplicationPoolRecycleTimes -ApplicationPoolName $apppoolname -RestartTimes $restartat

或

appcmd.exe set config  -section:system.applicationHost/applicationPools /+"[name='test1'].recycling.periodicRestart.schedule.[value='07:00:00']" /commit:apphost

    appcmd.exe set config  -section:system.applicationHost/applicationPools /+"[name='test1'].recycling.periodicRestart.schedule.[value='18:25:00']" /commit:apphost

或

 Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/applicationPools/add[@name='test1']/recycling/periodicRestart/schedule" -name "." -value @{value='07:00:00'}

Add-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/applicationPools/add[@name='test1']/recycling/periodicRestart/schedule" -name "." -value @{value='18:25:00'}

以上脚本均使用 IIS 10 (Windows 10) 和 IIS 8.5(windows server 2012r2) 进行测试

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2018-07-20
    • 2013-10-02
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多