As a systems administrator, having to sit and wait at the terminal for a job to finish is frustrating. In this hands-on lab, we run our PowerShell cmdlets as a background task, so you can get your prompt back and continue with your work. You can then retrieve the job at a later time, allowing you to check the status and perform actions with the resource upon completion.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Log in to the Linux VM
Open a new terminal.
Copy the public IP address provided with this hands-on lab.
In the terminal, connect to the VM:
ssh cloud_user@<PUBLIC_IP_OF_THE_VM>
Once logged in, start the PowerShell prompt:
pwsh
- Install the Az Module and Connect to Azure
Install the module:
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Enter
Y
to continue installing from the PowerShell gallery.From the PowerShell prompt, connect to Azure:
Connect-AzAccount
Go to
https://microsoft.com/devicelogin
and enter the code provided in the terminal.Enter the Azure Portal username and password provided with this hands-on lab.
- Create the VM as a Background Task
Create a new Azure VM as a job:
$job = New-AzVM -ResourceGroupName '<RESOURCE_GROUP_IN_THE_LAB>' -Name 'mynewVM' -Location 'westus' -AsJob -ImageName UbuntuLTS
Check the status of the job:
Get-Job
Pass the output of the job to a new variable:
$vm = Receive-Job $job
Once the job is complete, connect to the new VM via SSH:
$fqdn = $vm.FullyQualifiedDomainName ssh <YOUR_USERNAME>@$fqdn