Slice a PowerShell array into groups of smaller arrays

Question:

I would like to convert a single array into a group of smaller arrays, based on a variable. So, 0,1,2,3,4,5,6,7,8,9 would become 0,1,2,3,4,5,6,7,8,9 when the size is 3.

My current approach:

Produces:

I would like it to be:

What am I missing?

Answer:

You can use ,$x instead of just $x.

The about_Operators section in the documentation has this:

Source:

Slice a PowerShell array into groups of smaller arrays by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply