PowerShell IIS如何使每个回收周期间隔2分钟



我需要设置IIS池每隔2分钟回收一次的所有时间。我想在PS中创建一个脚本,为我设置。它看起来是这样的:">

$AppPool = Get-IISAppPool
$AppPoolName = $AppPool | select -ExpandProperty name
foreach ($pool in $AppPoolName) {
#Set-ItemProperty -Path IIS:AppPools$pool -Name recycling.periodicRestart.time -Value 3.00:00:00
}

我如何每次增加2分钟?价值3.00:00:00价值3.00:02:00价值3.00:04:00等

使用的格式是TimeSpan对象在使用.ToString('c')时输出的格式。

你可以像

那样在循环中给TimeSpan增加2分钟
$time = New-TimeSpan -Days 3 -Hours 0 -Minutes 0 -Seconds 0
foreach ($pool in $AppPoolName) {
Set-ItemProperty -Path IIS:AppPools$pool -Name recycling.periodicRestart.time -Value $time.ToString('c')
$time = $time.Add((New-TimeSpan -Minutes 2))
}

最新更新