# "chunking" foreach loops

**URL:** <https://forums.powershell.org/t/chunking-foreach-loops/12748>\
**Category:** PowerShell Help\
**Created:** [June 19, 2019, 8:45am UTC](https://forums.powershell.org/t/chunking-foreach-loops/12748 "2019-06-19T08:45:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![an0nemus](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@an0nemus](https://forums.powershell.org/u/an0nemus)\
**Post date:** [June 19, 2019, 8:45am UTC](https://forums.powershell.org/t/chunking-foreach-loops/12748/1 "2019-06-19T08:45:19Z")

</div>

say I have a list of 100 servers.

if I’m doing something small (say a test-path)

```
$servers=(get-content servers.txt)
foreach ($s in $servers){
write-host $s
test-path \$s\whatever
}
```

Then I just let it run.

How would I tell powershell to grab X servers do the loop, and then grab the next x until completed.

I feel like the answer should be simple, but I’m just not seeing it.

---

<div class="post-metadata">

**Author:** ![an0nemus](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@an0nemus](https://forums.powershell.org/u/an0nemus)\
**Post date:** [June 19, 2019, 9:31am UTC](https://forums.powershell.org/t/chunking-foreach-loops/12748/2 "2019-06-19T09:31:07Z")

</div>

I should have kept looking, I found an older topic on here that answered my question:  
[https://powershell.org/forums/topic/work-an-array-in-batches-of-5/](https://powershell.org/forums/topic/work-an-array-in-batches-of-5/)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/chunking-foreach-loops/12748/3 "2024-05-16T20:32:07Z")

</div>


