Start-ThreadJob
noun
say it: “START THRED jahb” /ˈstɑrt ˈθrɛd ˌdʒɑb/
A PowerShell command that runs a block of code as a background job inside the same PowerShell, giving you the prompt back at once.
What does Start-ThreadJob do?
Start-ThreadJob hands a script block to a background job and gives you your prompt back at once, like dropping a bag at the dry cleaner's and picking it up later. Get-Job shows whether it's still running, and Receive-Job collects what it printed. It comes with PowerShell 7.
$job = Start-ThreadJob -Name resize -ScriptBlock { Get-ChildItem -Filter *.jpg | ForEach-Object { .\resize-photo.ps1 -Path $_.FullName } }
Get-Job # State: Running
In a sentence
- “Sam gave the Start-ThreadJob job the name resize, so Sam could ask for it later by name.”
- “Start-ThreadJob resized the club's photos while Sam kept using the window.”
Level: Journeyman · More PowerShell terms at this level
Updated