Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

Parallel Execution · PowerShell Automation

Direct answer

Parallel execution in PowerShell 7 uses ForEach-Object -Parallel with -ThrottleLimit, while Invoke-Command runs on many remote computers at once.

When to use this

Use this when running PowerShell work in parallel.

First 30 seconds

1. Parallel execution speeds up multi-target work.

2. Set ThrottleLimit to protect targets.

3. Use $using: for variables.

4. Collect errors per item.

5. Thread safety for shared data.

Operational verification

items → parallel runspaces/remoting → results

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
PowerShell 7.5/current
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPowerShell 7.5/current · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when running PowerShell work in parallel.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

Measure a representative sequential baseline, then test the same workload with explicit -ThrottleLimit. Record item identifiers in outputs so results can be correlated despite completion order. Inspect errors per work item and verify final target state/count independently, especially if one terminating error does not cancel all other parallel instances.

Step 2 Common mistakes Narrow the fault
  • ForEach-Object -Parallel without throttle.
Step 3 Where it fails Narrow the fault

Parallel execution can amplify API throttling, lock contention and partial failure. A terminating exception in one parallel scriptblock may not stop siblings. Keep worker isolation, shared-state safety, throttle policy, per-item results and final convergence as separate evidence layers.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • ForEach-Object -Parallel works in PowerShell 7.
  • -ThrottleLimit controls concurrency.
  • Use $using: to pass variables in.
Key checks
  • 1..10 | ForEach-Object -Parallel { $_ } -ThrottleLimit 5 — PowerShell 7 parallel
  • Invoke-Command -ComputerName <list> -ThrottleLimit 32 — remote fan-out
  • Start-ThreadJob — threads
ReferenceWhy it matters1 section · depth on demand

In depth

Parallel execution in PowerShell runs work against many targets concurrently. In PowerShell 7, ForEach-Object -Parallel with a throttle limit is the simplest option; Invoke-Command against many computers is parallel by default (32 at a time).

$servers = Get-Content servers.txt
$results = $servers | ForEach-Object -Parallel {
  $r = Test-NetConnection $_ -Port 443 -WarningAction SilentlyContinue
  [pscustomobject]@{ Server = $_; Https = $r.TcpTestSucceeded }
} -ThrottleLimit 20
$results | Where-Object { -not $_.Https }
Invoke-Command -ComputerName $servers -ThrottleLimit 50 -ScriptBlock { Get-HotFix | Select-Object -Last 1 }

Variables from the parent scope need $using: inside -Parallel blocks, and shared collections must be thread-safe ([System.Collections.Concurrent.ConcurrentBag[object]]).

ReferenceImportant terms & boundaries1 section · depth on demand

PowerShell mechanics

ForEach-Object -Parallel in PowerShell 7 runs scriptblocks in separate runspaces on process threads and uses a runspace pool by default in current versions. ThrottleLimit controls concurrent scriptblocks for that invocation, $using: exposes caller variables to parallel code, and output/error ordering is nondeterministic across parallel workers. ThreadJob uses a related in-process isolation model with different orchestration surfaces.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Authoring and lifecycle

Parallelize work only when task duration or I/O wait exceeds runspace coordination overhead. Cap concurrency according to target/API limits, avoid unsynchronized mutation of shared non-thread-safe objects, and make each work item independently retryable where possible. Treat rate limits, connection pools and remote-service quotas as part of the concurrency design.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PowerShell 7.5/current 7.5/currentMinimal authored PowerShell pattern for Parallel Execution

Assumptions: Review target identity, permissions and environment before mutation.

$results = $items | ForEach-Object -Parallel { Invoke-Work $_ } -ThrottleLimit 4
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPowerShell 7.5/current 7.5/current

Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.5 · confidence 94%
Embedded reference data

Quick lookup tables

Parallel Execution · PowerShell operational reference

Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.

BoundaryParallel Execution reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

Output and errors can arrive in nondeterministic order; sequence on screen is not input sequence. $using: can expose references to objects that require thread-safe use, and runspace-local module/session state may differ from the caller. Measure elapsed time plus correctness rather than assuming parallel means faster.

Confirmation

Confirm action

Continue?