See if this work can work as needed (I assume your element n is the $obj element)
$ obj | % {$ i = 0; $ j = 0; $batches=@ {}}
if ($ i! = 3 and $ batches ["Batch $ j"]) {$ batches ["Batch $ j"] + = $ _; $ i + = 1}
else {$ i = 1; $ j + = 1; $ batches ["Batch $ j"] =@ ($ _)}
} {$ batches}
Should return HashTable ( $batches ) with keys such as "Batch 1" , "Batch 2" , ... each key is associated with an array of three elements.
source share