Azure PowerShell depends on connecting to an Azure cloud and waiting for responses, so most of these
cmdlets block your PowerShell session until they get a response from the cloud. PowerShell Jobs let
you run cmdlets in the background or do multiple tasks on Azure at once, from inside a single
PowerShell session.
This article is a brief overview of how to run Azure PowerShell cmdlets as PowerShell Jobs and check
for completion. Running commands in Azure PowerShell requires the use of Azure PowerShell contexts,
which are covered in detail in Azure contexts and sign-in credentials. To
learn more about PowerShell Jobs, see
About PowerShell Jobs.
Azure contexts with PowerShell jobs
PowerShell Jobs are run as separate processes without an attached PowerShell session, so your Azure
credentials must be shared with them. Credentials are passed as Azure context objects, using one of
these methods:
Automatic context persistence. Context persistence is enabled by default and preserves your
sign-in information across multiple sessions. With context persistence enabled, the current Azure
context is passed to the new process:
Enable-AzContextAutosave # Enables context autosave if not already on
$vmadmin = Get-Credential
Start-Job {
New-AzVM -Name MyVm -Credential $Using:vmadmin
}
Provide an Azure context object with any Azure PowerShell cmdlet that has an AzContext
parameter:
If context persistence is disabled, the AzContext parameter is required.
Use the AsJob parameter provided by some Azure PowerShell cmdlets. This switch automatically
starts the cmdlet as a PowerShell Job, using the active Azure context:
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
Azure PowerShell feedback
Azure PowerShell is an open source project. Select a link to provide feedback: