How to Install the Azure Az PowerShell Module

The Az PowerShell module was released in December of 2018 and is now the recommended module for managing Microsoft Azure. AzureRM is the previous PowerShell module for managing Azure which has been deprecated but will continue to be supported until February of 2024.

Windows PowerShell 5.1, PowerShell Core 6, PowerShell 7, and higher are supported by the Az PowerShell module. Windows 10 version 1607 and higher has Windows PowerShell 5.1 installed by default.

Determine if the version of PowerShell you're running meets the minimum requirements before attempting to install the Az PowerShell module.

1$PSVersionTable.PSVersion

az-install1a.jpg

The .NET Framework 4.7.2 or higher is also required by the Az PowerShell module on Windows. The version of the .NET Framework needs to be verified before installing the Az PowerShell module because Windows PowerShell 5.1 only requires the .NET Framework 4.5 or higher.

Verify the .NET Framework 4.7.2 or higher is installed.

1(Get-ItemProperty -Path 'HKLM:\Software\Microsoft\NET Framework Setup\NDP\v4\Full' -ErrorAction SilentlyContinue).Release -ge 461808

az-install2a.jpg

Previously there were full and client versions of the NET Framework, but beginning with .NET Framework 4.5, the client version was discontinued so there's no longer a reason to check both registry entries.

The installation itself is simple from the PowerShell Gallery.

1Install-Module -Name Az -Force

az-install3a.jpg

The previous command will install the Az module for all users and requires admin rights. The official Microsoft documentation recommends only installing it for the current user by specifying the Scope parameter with CurrentUser as its value which does not require admin rights.

The official Microsoft documentation also states that you can't have both the AzureRM and Az PowerShell modules installed for Windows PowerShell 5.1 at the same time. Their recommendation is to install the Az module for PowerShell 7 or higher if you already have the AzureRM module installed for Windows PowerShell.

Install them both in Windows PowerShell at your own risk!

Clearly, you can have them both installed at the same time as shown in the following example.

1Get-InstalledModule -Name Az, AzureRM

az-install4a.jpg

While they didn't specify why, many assume that it's due to the ability to enable AzureRM aliases in the Az module for backwards compatibility. That conclusion is completely fabricated and isn't a factor due to the way command precedence works in PowerShell. If commands with the same name exist, alias are executed first, followed by functions, cmdlets, and then native Windows commands.

Let's see what happens when I have both modules installed and enable AzureRM aliases in the Az PowerShell module.

1Enable-AzureRmAlias

az-install7a.jpg

Notice that although I have both modules installed, when I execute an AzureRM command, it actually executes the command in the Az module via its alias instead of the command in the AzureRM module.

1Trace-Command -Expression {Connect-AzureRmAccount} -Name CommandDiscovery -PSHost | Out-Null

az-install6a.jpg

If the AzureRM module is imported first, an error will be generated when you try to import the Az module.

1Import-Module -Name Az

az-install8a.jpg

If you attempt to import the AzureRM module after the Az module, a different error is generated.

1Import-Module -Name AzureRM

az-install9a.jpg

Removing the module within the same session and then trying to import the other one doesn't clear up the problem either. If you are going to have both installed for some reason in Windows PowerShell, you'll either need to close and reopen your PowerShell session when switching between the two or have two separate sessions open.

If you no longer need the AzureRM module, you always have the option of de-installing it as referenced in one of the previous error messages. If you don't use the Uninstall-AzureRm command and decide to use another method to de-install the AzureRM module, be sure to also remove the other 53 modules that it installs.

1Get-InstalledModule -Name AzureRM*

az-install5a.jpg

Microsoft articles containing addition information:

Be sure to read my previous blog article Setting Dependencies on the Azure PowerShell Module which shows that the Az module is simply a wrapper containing 54 PowerShell modules for individual Azure products.

µ