-Parallel is a PowerShell 7 parameter for ForEach-Object that runs the script block concurrently for multiple input objects instead of sequentially. It helps shorten long-running batches, although result order is not guaranteed. section 15.4 section 23.1.3
Compare sequential and parallel work
Pipe 1..5 to ForEach-Object with a two-second delay to measure roughly 10 seconds. Add -Parallel and the same work takes roughly 2 seconds. For larger batches, set -ThrottleLimit 10 to allow ten script blocks at once. section 23.1.3 section 15.4
Account for these behaviors when using -Parallel:
- The default throttle limit is five concurrent script blocks; adjust it with -ThrottleLimit. section 15.4
- Each parallel script block uses a new runspace, which can reduce performance for resource-intensive work. section 23.1.3
