Problem
You want to create an array of arrays, or an array of multiple dimensions.
Solution
To create a jagged multidimensional array (an array of arrays), use the @( ) array syntax:
PS >$jagged = @(
>> (1,2,3,4),
>> (5,6,7,8)
>> )
>>
PS >$jagged[0][1]
>>2
PS >$jagged[1][3]
>>8
To create a (nonjagged) multidimensional array, use the NewObject cmdlet:
PS >$multidimensional = NewObject "int32[,]" 2,4 PS >$multidimensional[0,1] = 2 PS >$multidimensional[1,3] = 8 PS > PS >$multidimensional[0,1] >>2 PS >$multidimensional[1,3] >>8
Discussion
Jagged and multidimensional arrays are useful for holding lists of lists/arrays of arrays. Jagged arrays are much easier to work with (and use less memory), while nonjagged multidimensional arrays are sometimes useful for dealing with large grids of data.
Since a jagged array is an array of arrays, creating an item in a jagged array follows the same rules as creating an item in a regular array. If any of the arrays are singleelement arrays, use the unary comma operator. For example, to create a jagged array with one nested array of one element:
PS >$oneByOneJagged = @( >> ,(,1) >> PS >$oneByOneJagged[0][0]