Working with jobs
The Start-Job
command in PowerShell provides a means of executing code asynchronously by creating a new PowerShell process for each job.
As each job executes within a new process, data cannot be implicitly shared between jobs. Any required modules, functions, and variables all need to be imported into each job.
Additionally, jobs might be considered resource heavy as each job must start a new PowerShell process.
PowerShell provides several commands to create and interact with jobs. In addition to the specific job commands, commands such as Invoke-Command
offer an AsJob
parameter.
The lifecycle of a job is most often controlled by Start-Job
and Remove-Job
.
Start-Job, Get-Job, and Remove-Job
You can use the Start-Job
command to execute a script block in a similar manner to Invoke-Command
, as shown in Chapter 14, Remoting and Remote Management. Also, you can use Start-Job
to execute a script using the FilePath
parameter.
When Start-Job
is...