Azure Az Module for Windows PowerShell, Core, and Cloud Shell Replaces AzureRM

powershell hero img

I’ve written quite a bit on using PowerShell to deploy and manage Windows Server virtual machines and other resources in the Azure cloud for Petri. But since those articles were published a lot has changed. Not only do we now have PowerShell Core, but Microsoft will no longer be adding features to Windows PowerShell, although it will still be supported. PowerShell Core is based on the .NET Core Framework, which means it also runs on Linux and MacOS. And if you want to start using PowerShell Core it can run side-by-side with Windows PowerShell on the same device.

For more information on PowerShell Core, see PowerShell Core 6.0 and Why Windows PowerShell Is No Longer Being Developed and 5 Things to Know About PowerShell Core on Windows on Petri.

Open Source Az PowerShell Module for Azure

The new open source Az module for PowerShell is cross-platform and replaces AzureRM, which Microsoft will continue to support. Az was released December 18th and Microsoft says that it will be updated twice a month, starting in the middle of January. New features for this release include:

  • Az runs on Windows PowerShell 5.1 and PowerShell Core (cross-platform)
  • Az is always up to date with the latest tooling for Azure services
  • Az ships in Cloud Shell
  • Az shortens and normalizes cmdlet names – all cmdlets use ‘Az’ as their noun prefix
  • Az simplifies and normalizes module names – data plane and management plane cmdlets for each service use the same Az module
  • Az ships with new cmdlets to enable script compatibility with AzureRM (Enable/Disable-AzureRmAlias)
  • Az enables device code authentication support, allowing login when remoting via a terminal to another computer, VM, or container

Install or Update Az PowerShell Module

The Az module can be installed from the PowerShell Gallery and it works in Windows PowerShell 5.1, PowerShell Core 6.0, and PowerShell Core 6.1. It’s possible to have the AzureRM and Az modules installed at the same time providing that you don’t enable aliases. If you are using Azure Cloud Shell, the Az module is now installed by default.

Install the new Az PowerShell module for Microsoft Azure (Image Credit: Russell Smith)
Install the new Az PowerShell module for Microsoft Azure (Image Credit: Russell Smith)

To install the Az module with global scope, run the Install-Module cmdlet as shown below in an elevated PowerShell window.

Install-Module -Name Az -AllowClobber

If you don’t have administrator rights or want to install for user scope only, add the -Scope parameter as shown here:

Install-Module -Name Az -AllowClobber -Scope CurrentUser

Once the Az module is installed, you can connect to your Azure subscription using the Connect-AzAccount cmdlet. This release doesn’t support user login with PSCredential, but the next version will support it for Windows PowerShell 5.1 only. Microsoft recommends signing in with a Service Principal when authenticating from a script. You can find more information about signing in with Service Principals on Microsoft’s website here.

To update the module, run Update-Module. Older versions of the module are not uninstalled but if you have more than one version of Az, by default module autoload and Import-Module load the latest version.

Update-Module -Name Az

To check which versions of the module you have installed, use Get-Module:

Get-Module -Name *Az.* -ListAvailable

Enable AzureRM Aliases

For the purposes of backwards compatibility, you can enable aliases to use the new Az module to run scripts that were designed for use with AzureRM. The only condition is that if you enable aliases, you must remove the AzureRM module. The command below enables aliases for all modules for the current user.

Enable-AzureRmAlias -Scope CurrentUser

The -Scope parameter has three possible values: Process, CurrentUser, and LocalMachine. You can disable aliases using Disable-AzureRmAlias.