Start-ThreadJob
Use Start-ThreadJob to run a script block on a thread inside the current process and return a job object.
Documentation: Microsoft Learn — PowerShell module reference
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Start-ThreadJob [-ScriptBlock] <ScriptBlock> [-Name <String>] [-ThrottleLimit <Int32>] [-ArgumentList <Object[]>] [-InitializationScript <ScriptBlock>] [-StreamingHost <PSHost>] [<CommonParameters>]- Stage 1Start-ThreadJob
-ScriptBlock -Name -ThrottleLimit -ArgumentList -InitializationScript -StreamingHost
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Start-ThreadJob -Name quick
Show reference output
Sample output · fictional data, shaped like the real thing
Id Name State -- ---- ----- 1 quick Running
Start-ThreadJob -ScriptBlock {
Show reference output
Sample output · fictional data, shaped like the real thing
Id Name State HasMoreData Location -- ---- ----- ----------- -------- 1 Job1 Running True localhost
Select Name, Version
Show reference output
Sample output · fictional data, shaped like the real thing
Name Version ---- ------- ThreadJob 2.0.3
Parameters
Parameter definitions:
-ScriptBlock-Name-ThrottleLimit-ArgumentList-InitializationScript-StreamingHost
Practical use and troubleshooting
Practical scenario: Use Start-ThreadJob when you need to run a script block on a thread inside the current process and return a job object. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: Command not recognised can mean ThreadJob is unavailable in that environment. Check Get-Module -ListAvailable ThreadJob and install the module only through the approved repository when needed. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Start-Job. Start-Job uses a separate process; Start-ThreadJob uses threads in the current process. Process jobs serialize results, while thread jobs share a process and its failure boundary. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Start-ThreadJob Use Start-ThreadJob to run a script block on a thread inside the current process and return a job object.
Next: Start-Job