The $using Scope Modifier in PowerShell

Put $using: in front of a variable name when a scriptblock runs somewhere else, such as a background job, a thread or a remote computer. It copies the value from your session into that code:

$city = 'Denver'
$job = Start-Job -ScriptBlock { "Sales report for $using:city" }
$job | Receive-Job -Wait -AutoRemoveJob

Output:

Sales report for Denver

In this tutorial, I’ll show you how the PowerShell $using scope modifier works with Start-Job, Start-ThreadJob, ForEach-Object -Parallel and Invoke-Command, what it can’t do, and how to fix its errors.

I ran every local example in PowerShell 7.6 and Windows PowerShell 5.1. Remote examples are code only, because WinRM is off on my test PC.

Why a background job can’t see your local variables

A job, a thread or a remote session starts with its own fresh set of scopes. Your variables don’t travel there unless you send them. Here’s what a job sees with and without $using:

$region = 'Mountain West'
$global:manager = 'Dana Reyes'
$job = Start-Job -ScriptBlock {
    "Plain:  [$region]"
    "Global: [$global:manager]"
    "Using:  [$using:region]"
}
$job | Receive-Job -Wait -AutoRemoveJob

Output:

Plain:  []
Global: []
Using:  [Mountain West]
Start-Job can't see a plain or global variable but reads it with the $using: scope modifier in PowerShell 7
Only the $using: line gets the value from the calling session (PowerShell 7)

Even the global variable came back empty. The job is a separate process with its own global scope, so global variables in PowerShell stay in the session that created them. PowerShell 5.1 printed the same lines.

Use $using: with Start-Job

Start-Job runs the scriptblock in a new PowerShell process on your computer. You can use as many $using: references as you need, and @using: splats a hashtable into a command:

$office = 'Austin'
$budget = 1250.75
$cutoff = [datetime]'2026-03-15'
$svc = @{ Name = 'Spooler' }
$job = Start-Job -ScriptBlock {
    "Office: $using:office"
    "Budget: USD $using:budget"
    "Cutoff: $(($using:cutoff).ToString('yyyy-MM-dd'))"
    "Service: $((Get-Service @using:svc).Name)"
}
$job | Receive-Job -Wait -AutoRemoveJob

Output:

Office: Austin
Budget: USD 1250.75
Cutoff: 2026-03-15
Service: Spooler
Start-Job reading local variables and splatting a hashtable with @using: in Windows PowerShell 5.1
Four local values read inside the job, including a splatted hashtable (Windows PowerShell 5.1)

Notice ($using:cutoff).ToString(). Wrap the reference in parentheses before you call a method on it. PowerShell 7 printed identical output.

The variab