Skip to main content
Code and think

PWSH ForEach-Object -Parallel

When using PowerShell and multiple commands that can be executed in parallel use ForEach-Object -Parallel {}.

Tips:

A clean example from the documentation is:

$Message = "Output:"

1..8 | ForEach-Object -Parallel {
    "$using:Message $_"
    Start-Sleep 1
} -ThrottleLimit 4

Output: 1
Output: 2
Output: 3
Output: 4
Output: 5
Output: 6
Output: 7
Output: 8

Reference