liveBook · Manning

-parallel

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

-Parallel is a ForEach-Object parameter that runs the supplied script block concurrently for multiple input objects.

-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

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains syntax, timing, throttling, result ordering, and runspace overhead through runnable examples.
Examples
Demonstrates delayed arrays, vault creation, Active Directory users, filename counting, and timing comparisons.
What it assumes
Assumes basic pipelines and ForEach-Object, while building parallel-processing awareness from practical commands.
What you can do after
Apply it via ForEach-Object to parallelize suitable batches and tune their concurrency.
How it connects
Connects ForEach-Object with Measure-Command, PowerShell jobs, throttle limits, and runspaces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.