Powershell: Two dimension arrays Powershell: Two dimension arrays powershell powershell

Powershell: Two dimension arrays


This is another case where PowerShell's array handling behavior may cause unexpected results.

I think you'll need to use the comma trick (the array operator) to get the desired result:

$values = @( ,("a", "b") )foreach($value in $values){  write-host "Value 0 =" $value[0]  write-host "Value 1 =" $value[1]}

Result:

Value 0 = aValue 1 = b

Actually all you need is this:

$values = ,("a", "b")

This article explains more about PowerShell's handling of arrays:

http://blogs.msdn.com/b/powershell/archive/2007/01/23/array-literals-in-powershell.aspx