Loading, please wait...

A to Z Full Forms and Acronyms

How to install Az module in PowerShell

Jun 01, 2020 Azure, Azure VM, PowerShell, 14307 Views
To resolve a very common issue while Az module in PowerShell is installed but not working

Objective:

To resolve a very common issue while Az module in PowerShell is installed but not working

Az is a new module, so the version has been reset to 1.0.0. Az module is simple, easy, and having many new cmdlets.

Why Microsoft introduced a new module Az?

The earlier versions of PowerShell were designed and based upon .Net Standard Library. Since PowerShell has now been a cross-platform utility. Microsoft has continuously put efforts to bring Azure support to all platforms; therefore, Azure PowerShell modules have to be updated which could support Standard Library and Core.

Now there are two flavors of PowerShell available.

  1. AzureRM – based on Standard Library (which would be officially maintained through December 2020)
  2. Az – based on Core therefore can be used on any platform and Azure too.

Currently, you can keep both the modules in your system. Both the modules will have their own collection of modules and can be accessed with different sets of commands.

Important Notes:

  1. PowerShell 7.x and later is the recommended version of PowerShell for use with Azure PowerShell on all platforms.
  2. If the AZ module is already installed on PowerShell 5.1 (default), then you have to uninstall it before using AZ module commands using pwsh

Problem statement

The following error occurred when I ran the Connect-AzAccount command in an integrated terminal under VS Code because I noticed the current PowerShell version was 5.1.x and here lies the problem.

Solution

It is recommended to update PowerShellGet because it has cmdlets for discovering, installing, updating, and publishing PowerShell packages. 

Before updating PowerShellGet, you should always install the latest NuGet provider.

https://docs.microsoft.com/en-us/powershell/scripting/gallery/installing-psget?view=powershell-7

PS D:\learning\azure> Install-Module -Name Az -AllowClobber -Scope AllUsers

on the shell:

There are chances that the issue will still persist because PowerShell Az module could have been installed over the version 5.1 but worth giving a try. If you face this issue, you have to remove the Az module first then install the .Net Global tool.

Install as a .NET Global tool

To install a .Net Global tool, you should visit the following link. There are a variety of installers available. You have to choose what you want. I have chosen Core.

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7

PS D:\Learning\Azure> pwsh
PowerShell 7.0.1
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/powershell
Type 'help' to get help.
PS D:\Learning\Azure>Go back to PowerShell 7.0 using pwsh command

 

Run the Connect-AzAccount and follow the instruction as given as WARNING

Finally, I got connected with my Azure account using PowerShell command

Thus I got the correct PowerShell version for using the Az module and have tested, I’m now able to use any Az cmdlets.

Thanks for reading this article

A to Z Full Forms and Acronyms