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 shared between jobs. Any required modules, functions, or variables all need to be imported into each job.
Additionally, jobs might be considered resource heavy as each job must start both a PowerShell process and a console window's host process.
PowerShell provides several commands to create and interact with jobs. In addition to the following commands, you can use Invoke-Command
with the AsJob
parameter when acting against remote systems.
The Start-Job, Get-Job, and Remove-Job commands
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 executed...