How to install Az PowerShell module correctly?

Az PowerShell is a powerful and convenient way to manage an Azure subscription with PowerShell scripts. It is an add-on module to the PowerShell scripting tool pre-installed with Windows. It is very useful for automating tasks and monitoring resources on the Azure cloud.

Let’s have a look at the steps to install the Az PowerShell correctly:

Step 1: The Az PowerShell module is only compatible with PowerShell 7.x and later versions. So first step is to make sure that we have the latest version of PowerShell.

To check the PowerShell version currently installed, please run the following command in PowerShell:

$PSVersionTable.PSVersion

This will return a table with the following information:

Check PowerShell Version

In the above example, the installed PowerShell version is 5.1, so we go to step 2.

Step 2 (Optional): Since PowerShell is an open-source project, it is available as a free download on Github. Please follow the instructions provided in the link below to install the latest version of PowerShell:

https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7.1

Step 3: Before we move forward, we would like to make sure that the PowerShell execution policy is set to RemoteSigned (less restrictive) :

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Step 4: Run the command below to install the Az module :

Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

Please note: Make sure that you are connected to the internet while running this command, since the command needs to download the Az PowerShell installation files.

Also, the command may take a while to show the installation progress bar (usually 2 to 3 minutes).

Step 5 (Optional): The PowerShell installation command above does not install all the available sub-modules of Az PowerShell by default. One of the important sub modules not installed by default, is the Az.Synapse sub-module, which is used for managing Azure Synapse Analytics service.

Use the script below to check if a particular submodule e.g. Az.Synapse is installed:

if (Get-Module -ListAvailable -Name Az.Synapse) {
Write-Host "Module exists"
}
else {
Write-Host "Module does not exist"
}

If the above code returns “Module does not exist”, Run the command below to install it:

Install-Module -Name Az.Synapse -Scope CurrentUser -Repository PSGallery -Force

Reference: https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-6.2.1#code-try-1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: