Powershell – Looping through objects in batches of 3

Question:

I have an object which contains 7 items.

I want to loop through in batches of 3. I do NOT want to use the modulus function, I actually want to be able to create a new object with just the 3 items from that batch. Pseudo code:

Regards,
ted

Answer:

Your pseudo code is almost real. I have just changed its syntax and used the range operator (..):

The output looks exactly as required.

Source:

Powershell – Looping through objects in batches of 3 by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply