Powershell多个阵列(noob)

时间:2013-11-13 20:42:29

标签: loops powershell

所以说我有2个阵列。

$Letters = ("A","B","C")
$Numbers = ("1","2","3")

你将如何构建一个foreach循环,使其有效:

foreach ($letter in $letters) {set-something $number} where I could do a pair of values such that

A设置为1B设置为2C设置为3,依此类推。甚至这叫什么?我以为它被称为嵌套循环,但是全部搜索,似乎这不是所谓的。非常感谢!

1 个答案:

答案 0 :(得分:4)

如果是Zip操作,那么这将解决问题:

C:\PS> $Letters | Foreach {$i=0} {@($_,$Numbers[$i++]}
A
1
B
2
C
3

但我想你可能想要这个:

C:\PS> $Letters | Foreach {$i=0;$ht=@{}} {$ht."$_"=$Numbers[$i++]}
C:\PS> $ht.A
1
C:\PS> $ht.B
2
C:\PS> $ht.C
3