CLI

Get started with the new Azure PowerShell Az module

The Azure PowerShell Az module is released since December 2018 and is currently available in Version 1.8.0.  It is the intended PowerShell module for interacting with Azure because the previous AzureRM module will no longer receive new features (it will continue to receive bug fixes until at least December 2020).

This article is for beginners and will show you how to install and update the Az PowerShell module, how to sign in and how to discover the available cmdlets.

Install the Azure PowerShell Az module

The Az module requires Windows PowerShell Version 5.1 or higher or PowerShell Core Version 6+. You can determine your PowerShell version using the following command:

$PSVersionTable.PSVersion

PsVersion

If you need to update or install PowerShell, see Installing various versions of PowerShell.

In case you have the old AzureRM module installed, please see How to migrate Azure PowerShell from AzureRM to the new Az Module.  You can determine whether you have the old AzureRM module installed using the following command:

Get-InstalledModule -Name AzureRM

GetInstalledModule

To install the new Az module, run the following command in an elevated session:

Install-Module -Name Az -AllowClobber

Update the Az module

You can download and install the newest version of the Az module from the online gallery using the Update-Module cmdlet. Please note, that this won’t deinstall any previous version.

Update-Module -Name "Az"

Sign in to Azure

The Az PowerShell Module uses the Connect-AzAccount cmdlet to sign in to Azure.
Use the cmdlet without any parameter for an interactive login to an Azure account:

Connect-AzAccount

You can also connect to Azure using a service principal account:

$secureClientSecret = ConvertTo-SecureString '{clientSecret}' -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential('{clientId}', $secureClientSecret )
Connect-AzAccount -ServicePrincipal -Credential $credential -TenantId '{directoryId}'

If you have multiple subscriptions, you can either set the desired one using the -SubscriptionId or -SubscriptionName Connect-AzAccount parameter:

Connect-AzAccount -SubscriptionName 'mbr_workshop'

ConnectWithSub

Or you can change the context after you signed in using the Set-AzContext cmdlet:

Set-AzContext 'mbr_workshop'

Discover the Az module cmdlets

We can use the Get-Module cmdlet to retrieve all available Az modules:

Get-Module Az.* -ListAvailable | Select-Object Name -Unique

GetModule

To discover the available cmdlets within a module we can use the Get-Command cmdlet. In this example, we browse all cmdlets within the Az.Account module:

Get-Command -Module Az.Accounts

GetCommand