I am wondering how one would tackle looping through a collection of objects, processing the elements of that collection in groups instead of singularly, as is the case in normal Foreach loops. For example, instead of this:
$items = get-vm
foreach ($item in $items) { do something }
I would like to do this:
$items = get-vm
foreach ((5)$item in $items) {do something}
Essentially, this statement intends to say foreach 5 items in items do some work.....
Can anyone show me the proper constructs required to accomplish this?
I've got this:
$array = 1..100
$group = 10
$i = 0
do {
$array[$i..(($i+= $group) - 1)]
'*****'
}
until ($i -ge $array.count -1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With