Running Azure PowerShell Cmdlets in PowerShell Jobs

1.75 hours
  • 3 Learning Objectives

About this Hands-on Lab

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
  1. Open a new terminal.

  2. Copy the public IP address provided with this hands-on lab.

  3. In the terminal, connect to the VM:

    ssh cloud_user@<PUBLIC_IP_OF_THE_VM>
  4. Once logged in, start the PowerShell prompt:

Install the Az Module and Connect to Azure
  1. Install the module:

    Install-Module -Name Az -AllowClobber -Scope CurrentUser
  2. Enter Y to continue installing from the PowerShell gallery.

  3. From the PowerShell prompt, connect to Azure:

  4. Go to and enter the code provided in the terminal.

  5. Enter the Azure Portal username and password provided with this hands-on lab.

Create the VM as a Background Task
  1. Create a new Azure VM as a job:

    $job = New-AzVM -ResourceGroupName '<RESOURCE_GROUP_IN_THE_LAB>' -Name 'mynewVM' -Location 'westus' -AsJob -ImageName UbuntuLTS
  2. Check the status of the job:

  3. Pass the output of the job to a new variable:

    $vm = Receive-Job $job
  4. Once the job is complete, connect to the new VM via SSH:

    $fqdn = $vm.FullyQualifiedDomainName
    ssh <YOUR_USERNAME>@$fqdn

Additional Resources

In this hands-on lab, you've been given a Linux VM to log in to with PowerShell already installed. Once you've logged in, you will perform the necessary commands to install the Az module, connect to the Azure portal, and create a new VM in the background. You can consider this hands-on lab complete when you've completed the following:

  • Logged in to the VM provided with this lab.
  • Installed the Az module and connected with Azure via the Azure credentials given.
  • Created a VM from within Azure, having issued the correct command to run the action as a job.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?