Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何增加foreach-Powershell(IIS)中项目的值_Powershell_Iis - Fatal编程技术网

如何增加foreach-Powershell(IIS)中项目的值

如何增加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

我有一个小脚本来设置一些应用程序池的回收时间值。问题是,我有大约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

    # 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}

}