如何增加foreach-Powershell(IIS)中项目的值
我有一个小脚本来设置一些应用程序池的回收时间值。问题是,我有大约190个项目,我宁愿使用脚本,而不是手动操作如何增加foreach-Powershell(IIS)中项目的值,powershell,iis,Powershell,Iis,我有一个小脚本来设置一些应用程序池的回收时间值。问题是,我有大约190个项目,我宁愿使用脚本,而不是手动操作 Import-Module WebAdministration #Getting all the AppPools $pools = Get-ChildItem -Path IIS:\AppPools $RestartTime = @("05:00", "15:00") ForEach ($pool in $pools) { $app_pool = $pool.name
Import-Module WebAdministration
#Getting all the AppPools
$pools = Get-ChildItem -Path IIS:\AppPools
$RestartTime = @("05:00", "15:00")
ForEach ($pool in $pools)
{
$app_pool = $pool.name
# Delete all existing scheduled recycle items
# Clear-ItemProperty IIS:\AppPools\$app_pool -Name Recycling.periodicRestart.schedule
# Checking the actual value
Write-Host $app_pool
(Get-ItemProperty -Path IIS:\\AppPools\$app_pool -name recycling.periodicRestart.schedule.collection) | select value
# Set the application pool to recycle at the time we want
# New-ItemProperty -Path "IIS:\AppPools\$app_pool" -Name Recycling.periodicRestart.schedule -Value @{value=$RestartTime}
}
我希望在上午5:00和下午3:00重新启动所有应用程序池,但在这些时间内增加特定应用程序池组的特定时间。i、 e:
- 应用程序池1-20:上午5:00和下午3:00
- 应用程序池21-40:上午5:10和下午3:10
- 应用程序池41-60:上午5:20和下午3:20
提前谢谢 你可以用循环计数器做一个有条件的循环,这是我的想法
Import-Module WebAdministration
#Getting all the AppPools
$pools = Get-ChildItem -Path IIS:\AppPools
$RestartTime = @("05:00", "15:00")
$count = 0
ForEach ($pool in $pools)
{
$app_pool = $pool.name
# Delete all existing scheduled recycle items
# Clear-ItemProperty IIS:\AppPools\$app_pool -Name Recycling.periodicRestart.schedule
if ($count -le 20){
$RestartTime = @("05:00", "15:00")
}
elseif ($count -gt 20 -and $count -le 40) {
$RestartTime = @("05:10", "15:10")
} else {
$RestartTime = @("05:20", "15:20")
}
$count++
# Checking the actual value
Write-Host $app_pool
(Get-ItemProperty -Path IIS:\\AppPools\$app_pool -name recycling.periodicRestart.schedule.collection) | select value
# Set the application pool to recycle at the time we want
# New-ItemProperty -Path "IIS:\AppPools\$app_pool" -Name Recycling.periodicRestart.schedule -Value @{value=$RestartTime}
}