嗨,我想运行for循环像下面在用于与的powershell环多阵列
$ a是GT 0和LT 5,$ b为GT 2和LT 7,I NNED这样循环结果(这是$ a和$ b)
这是1和3
这是2和4
这是3和5
这是4和6
希望有人能帮助我,谢谢
嗨,我想运行for循环像下面在用于与的powershell环多阵列
$ a是GT 0和LT 5,$ b为GT 2和LT 7,I NNED这样循环结果(这是$ a和$ b)
这是1和3
这是2和4
这是3和5
这是4和6
希望有人能帮助我,谢谢
使用for循环和分配$a + 2
到$b
:
for ($a = 1; $a -lt 5; $a++)
{
$b = $a +2;
Write-Host "this is $a and $b"
}
输出:
this is 1 and 3
this is 2 and 4
this is 3 and 5
this is 4 and 6
谢谢Jessen,但我注意到“$ a”不能放入“[]”,我想简化我的脚本,如下所示 $ array =(Get-Content D:\ new.txt -TotalCount -1)[ - 1] $ data = $ array.split(“”) $ d8 = $ data [8] $ d9 = $ data [9] $ d10 = $ data [10] $ d11 = $ data [11] $ d12 = $ data [12] $ d13 = $ data [13] if($ d8 -eq“CPULd”) { “SVR360't $ d8't $ d9”| out-file“D:\ result .txt“-append -Encoding ASCII ”SVR360't $ d10't $ d11“| out-file”D:\ result.txt“-append -Encoding ASCII ”SVR360't $ d12't $ d13“| out-file“D:\ result.txt”-append -Encoding ASCII } 如何简化和使它看起来干净? –