Run a Get-Counter job providing a variable that contains the string of the counter you wish to capture for the "-Counter" parameter as per the below example.
$t = "\LogicalDisk(C:)\% Free Space"
$diskJob = Start-Job -ScriptBlock {Get-Counter -Counter "$t" -SampleInterval 10 -MaxSamples 25 | foreach {$_.CounterSamples} }
Same behavior as if a string was typed out such as the below.
$diskJob = Start-Job -ScriptBlock {Get-Counter -Counter "\LogicalDisk(C:)\% Free Space" -SampleInterval 10 -MaxSamples 25 | foreach {$_.CounterSamples} }
Job shows completed immediately.

Name Value
---- -----
PSVersion 5.1.14393.2430
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.2430
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Jobs run in a different process and don't inherit variables automatically. If you use the using modifier, the value will be retrieved from the parent process (though it will be serialized).
$t = "\LogicalDisk(C:)\% Free Space"
$diskJob = Start-Job -ScriptBlock {
Get-Counter -Counter $using:t -SampleInterval 10 -MaxSamples 25 |
ForEach-Object { $_.CounterSamples }
}
Jobs run in a different process and don't inherit variables automatically. If you use the
usingmodifier, the value will be retrieved from the parent process (though it will be serialized).$t = "\LogicalDisk(C:)\% Free Space" $diskJob = Start-Job -ScriptBlock { Get-Counter -Counter $using:t -SampleInterval 10 -MaxSamples 25 | ForEach-Object { $_.CounterSamples } }
Oh wow, that is indeed the solution. Very interesting that Jobs run in a different process, I didn't see that mentioned in the docs anywhere when I was researching. Thanks!
Most helpful comment
Jobs run in a different process and don't inherit variables automatically. If you use the
usingmodifier, the value will be retrieved from the parent process (though it will be serialized).