Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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
Powershell 在Where语句中使用数字范围_Powershell_Loops_Foreach_Numbers_Where - Fatal编程技术网

Powershell 在Where语句中使用数字范围

Powershell 在Where语句中使用数字范围,powershell,loops,foreach,numbers,where,Powershell,Loops,Foreach,Numbers,Where,我试图在迭代foreach循环时,在Where语句中使用一个数字范围。$i变量用于分离循环的各个部分,具体取决于循环经过的迭代次数 $a = 11..20 $i = 0 $PoolSW = "" $PoolSW2 = "" $PoolSW3 = "" foreach ($Pool in $PoolTable) { $i++ [Array]$PoolSW += "Statistic.Pool$($Pool.Name -replace "-","_"): $(Get-PoolHea

我试图在迭代
foreach
循环时,在
Where
语句中使用一个数字范围。
$i
变量用于分离循环的各个部分,具体取决于循环经过的迭代次数

$a = 11..20
$i = 0
$PoolSW = ""
$PoolSW2 = ""
$PoolSW3 = ""

foreach ($Pool in $PoolTable) {
    $i++
    [Array]$PoolSW += "Statistic.Pool$($Pool.Name -replace "-","_"): $(Get-PoolHealth -BooleanState $Pool.Enabled)" | where {$i -le 10}
    [Array]$PoolSW2 += "Statistic.Pool$($Pool.Name -replace "-","_"): $(Get-PoolHealth -BooleanState $Pool.Enabled)" | where {$i -eq $a}
    [Array]$PoolSW3 += "Statistic.Pool$($Pool.Name -replace "-","_"): $(Get-PoolHealth -BooleanState $Pool.Enabled)" | where {$i -gt 20}
}

变量
$PoolSW
$PoolSW3
工作正常,不幸的是,我不知道如何让
$PoolSW2
正常工作。我尝试了
其中{$I-eq 11..20}
我尝试了逗号分隔数字,我还尝试了
-contains

您可以使用如下范围-

... | where {$i -ge 11 -and $i -le 20}

在运算符中使用
--

... | where {$i -in 11..20}

您可以使用以下范围:

... | where {$i -ge 11 -and $i -le 20}

运算符中使用
--

... | where {$i -in 11..20}

试试
where{$i-in11..20}
。试试
where{$i-in11..20}