PowerShell 7 and ForEach-Object -Parallel

Process independent work in parallel with PowerShell 7 and a sensible throttle.

If you are still using PowerShell 5, you are missing one of the greatest features.

In PowerShell 7, we have the option to do:

1$something | ForEach-Object -Parallel {
2    "do the thing"
3} -ThrottleLimit 10

This lets you process objects in parallel rather than sequentially. $_ is the current item, just like a regular ForEach-Object.

-ThrottleLimit is great for those memory-intensive operations. The default is 5; 10 here is an example, not a magic number. Choose a limit that fits the work, available memory, and any service throttling.

There is overhead to parallel work, so a trivial operation can be slower than running it sequentially. Measure the actual workload before assuming more parallelism will help.

The blocks run in separate runspaces, and output can arrive out of order. Use $using:variableName to reference an outside variable, and don’t have multiple workers mutate ordinary shared collections. Keep iterations independent or use thread-safe objects.

Read all about it here: ForEach-Object documentation.

Original post: 31 July 2024. Related posts: parallel processing, ThrottleLimit example, and memory-intensive operations. Documentation checked 14 October 2026.

Wednesday, October 14, 2026 Wednesday, July 31, 2024