Skip to content
Back to skills

Powershell Parallel Execution

ASecurity

Use when running tasks in parallel with PowerShell.

  • 2 stars
  • 0 votes
  • 0 copies
  • 6 views
  • Added September 10, 2026
ai-agentsgoshell

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill powershell-parallel-execution --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Powershell Parallel Execution?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Powershell Parallel Execution
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-powershell-parallel-execution/badge)](https://www.skillsdirectory.com/skills/loopyluci-powershell-parallel-execution)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: powershell-parallel-execution
description: "Use when running tasks in parallel with PowerShell."
category: software-development
tags: [powershell, parallel, threading, runspace, jobs]
---
# PowerShell Parallel Execution

Running tasks concurrently in PowerShell.

## ForEach-Object -Parallel (PS 7+)

```powershell
# Simple parallel
Get-ChildItem "*.jpg" | ForEach-Object -Parallel {
    $_.Name + " processed"
} -ThrottleLimit 5

# With variables (use $using: scope)
$folder = "C:\images"
Get-ChildItem "*.jpg" | ForEach-Object -Parallel {
    $dest = Join-Path $using:folder "processed"
    # process $_
} -ThrottleLimit 10
```

## Start-ThreadJob (PS 6+, cross-platform)

```powershell
$jobs = @()
$paths = @("C:\logs1", "C:\logs2")

foreach ($path in $paths) {
    $jobs += Start-ThreadJob -ScriptBlock {
        param($p)
        Get-ChildItem $p -Recurse | Measure-Object -Property Length -Sum
    } -ArgumentList $path
}

# Wait for all
$results = $jobs | Receive-Job -Wait -AutoRemoveJob
```

## Classic Job System (PS 3+, slower)

```powershell
$j1 = Start-Job -ScriptBlock { Start-Sleep 5; "Job 1 done" }
$j2 = Start-Job -ScriptBlock { Start-Sleep 3; "Job 2 done" }
$results = $j1, $j2 | Wait-Job | Receive-Job
$j1, $j2 | Remove-Job
```

## Runspaces (advanced, fastest)

```powershell
$runspacePool = [RunspaceFactory]::CreateRunspacePool(1, 5)  # min 1, max 5
$runspacePool.Open()

$ps = [PowerShell]::Create()
$ps.RunspacePool = $runspacePool
$ps.AddScript({ param($x) $x * 2 }).AddArgument(21)

$async = $ps.BeginInvoke()
$result = $ps.EndInvoke($async)
$ps.Dispose()
$runspacePool.Dispose()
```

## Throttle Control

```powershell
# ForEach-Object -Parallel already throttles via -ThrottleLimit
# Default ThrottleLimit = 5

# For ThreadJob, manage manually
$maxConcurrent = 3
$batch = @()
Get-ChildItem "C:\logs" -Directory | ForEach-Object {
    $batch += Start-ThreadJob -ScriptBlock { param($d) Get-ChildItem $d -Recurse | Measure-Object } -ArgumentList $_.FullName
    if ($batch.Count -ge $maxConcurrent) {
        $batch | Receive-Job -Wait -AutoRemoveJob
        $batch = @()
    }
}
# Process remaining
if ($batch) { $batch | Receive-Job -Wait -AutoRemoveJob }
```

## Pitfalls

- **$using:scope** required in ForEach-Object -Parallel for parent variables
- **No interactive cmds** inside parallel blocks -- no Read-Host, no Show-Forms
- **ThreadJob** uses threads, not processes -- watch for thread-safe issues
- **Start-Job** is heavy (each job = new process) -- avoid for many small tasks
- **Runspaces** are most efficient but need careful resource management

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.