Runspace

noun

say it: “RUN-spays” /ˈrʌnˌspeɪs/

A separate PowerShell running inside the one you use, with its own variables, as each background thread job and parallel run gets.

What is a runspace in PowerShell?

A runspace is a PowerShell of its own, running inside the one you typed in. It has its own variables, so a thread job or a ForEach-Object -Parallel block can't see yours: write $using: in front of a variable to hand it in.

$resizer = "$HOME\terminal-practice\photos\resize-photo.ps1"
Get-ChildItem -Filter *.jpg | ForEach-Object -Parallel { & $using:resizer -Path $_.FullName } -ThrottleLimit 4

In a sentence

  • “A thread job starts in a new runspace but in the same window's folder.”
  • “Each photo ran in a runspace of its own, so the block couldn't see $resizer without $using:.”

Level: Freelancer · More PowerShell terms at this level

Updated