How To Install Azure PowerShell

How To Install Azure PowerShell
Azure PowerShell module

In this Azure tutorial, we will discuss How to install Azure PowerShell, Along with this, we will also discuss a few other topics like below

  • Azure PowerShell Module
  • Cloud Shell
  • Installing the Azure PowerShell Module
  • How to install Azure PowerShell module offline
  • Download Azure PowerShell MSI
  • Update the Azure PowerShell Module
  • Install AzureRM PowerShell
  • Connect to Azure AD PowerShell

How To Install Azure PowerShell

Well, let’s discuss a very interesting topic i.e How to install Azure PowerShell.

If you will think now about what exactly Azure PowerShell is? Azure PowerShell contains different sets of modules that actually provide sets of PowerShell cmdlets to manage the Azure resources along with Windows PowerShell.

If you have any requirement to build any automation script for any of the Azure resources you are working with, then Azure PowerShell is the best option here for this requirement. Basically, to manage the Azure resources with the cmdlets, there are two ways

Azure PowerShell Module

You can install Azure PowerShell module on your local machine and then you can use different PowerShell cmdlets to manage different Azure resources.

Cloud Shell

Once you logged in to the Azure Portal, you can use the Azure Cloud Shell with a single click in the Browser itself. To access the Azure Cloud Shell, you can follow the below steps

Log in to the Azure Portal, and click on the Cloud Shell icon as highlighted below which is present just before the Directory + Subscription button.

How to install Azure PowerShell module
How To Install Azure PowerShell

Ohk, before starting the installation of the Azure PowerShell module, we should discuss the Prerequisites needed for Installing the Azure PowerShell Module.

Prerequisites

  • You must have Windows PowerShell version 5.1 or later installed on your machine. One point to note down here is, if you are using Windows 10, you already have PowerShell 5.1 installed on your machine by default.
  • Make sure to install the .NET Framework 4.7.2 or later version on your local machine.
  • You must install the latest version of PowerShellGet. If you don’t have the latest version of PowerShellGet installed on your machine, then you can use the below PowerShell cmdlet to install the latest version of PowerShellGet.
PS C:\WINDOWS\system32> Install-Module -Name PowerShellGet -Force

Installing the Azure PowerShell Module

Well, we need to install the Azure PowerShell module now. We can install the Azure PowerShell module from the PowerShell Gallery, where all the latest Azure PowerShell modules are available.

As part of the Azure PowerShell module installation, you can install the AzureRM or Az module. One very important point to note down here is, it is not suggested to install both the AzureRM and Az modules for PowerShell 5.1 on Windows at the same time.

Az is a replacement for the AzureRM module. Az is always up to date with the latest stuff for Azure services. I feel it’s better to go with the Az module.

Follow the below steps to install the Azure PowerShell module.

Sep-1: Open the PowerShell ISE using the Run as Administrator mode.

install microsoft azure powershell module

Step-2: Run the below PowerShell cmdlet to make sure you have the PowerShell Get-Module installed on your local machine.

PS C:\WINDOWS\system32> Get-Module PowerShellGet -list | Select-Object Name,Version,Path
install Azure PowerShell

Step-3: Now install the Azure PowerShell Az Module for the current user only using the below PowerShell cmdlet. Make sure that you have opened your PowerShell ISE as Run as administrator mode.

if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
    Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
      'Az modules installed at the same time is not supported.')
} else {
    Install-Module -Name Az -AllowClobber -Scope CurrentUser
}

Now click on the Yes to All button to confirm the installation of the Azure Az module.

Install the Azure PowerShell module

Step-4: You can also install the Azure PowerShell Az Module for all users’ scope using the below PowerShell cmdlet.

if ($PSVersionTable.PSEdition -eq 'Desktop' -and (Get-Module -Name AzureRM -ListAvailable)) {
    Write-Warning -Message ('Az module not installed. Having both the AzureRM and ' +
      'Az modules installed at the same time is not supported.')
} else {
    Install-Module -Name Az -AllowClobber -Scope AllUsers
}

Click on the Yes to All button to confirm the installation of the Azure Az module for the all users scope.

microsoft azure powershell module sdk

Now, once you will run the above PowerShell script, it will start installing the Azure Az module as shown below

how to install azure powershell on windows 10

Now to make sure, the Azure Az module is installed on your machine, run the below PowerShell cmdlet that will show you the list of modules installed on your machine.

Get-InstalledModule
how to check if azure az module is installed

How to install Azure PowerShell module offline

If by chance, you are no able to connect to the PowerShell Gallery due to some Environmental issues, then you can also able to install the Azure PowerShell module offline. Follow the below instructions for installing the Azure PowerShell module offline.

But, before the installation, you should know the Prerequisites needed for the installation.

Prerequisites

  • You must have Windows PowerShell version 5.1 installed on your machine. One point to note down here is, if you are using Windows 10, you already have PowerShell 5.1 installed on your machine by default.
  • Make sure to install the .NET Framework 4.7.2 or later version on your local machine.

Now once you are ready with the Prerequisites, we can start the installation of the Azure PowerShell module using the below instruction

Download Azure PowerShell MSI

Download the MSI package from the below path

https://github.com/Azure/azure-powershell/releases/tag/v3.7.0-March2020

You can download the 64-bit installer file. Once it has been downloaded successfully, you can double click on the installer file and then accept the License agreement and finally, click on the Install button to start the installation of the Azure PowerShell module.

Now to start working with the Azure PowerShell, run the below PowerShell cmdlet which will prompt you to log in with your Azure Credentials.

PS C:\WINDOWS\system32> Connect-AzAccount

This is how you can install the Azure PowerShell module offline using the above instruction.

Update the Azure PowerShell Module

Now once the installation of the Azure PowerShell module is completed successfully, anytime you want to update the Azure Power module to the latest version, you can run the below cmdlet.

PS C:\WINDOWS\system32> Update-Module -Name Az

Once you will execute the above PowerShell cmdlet, your Azure PowerShell version will get updated to the latest version.

Sign-in into Azure PowerShell

You can connect or sign into Azure PowerShell using the below PowerShell cmdlet

PS C:\WINDOWS\system32> Connect-AzAccount

Once you will execute the above PowerShell cmdlet, it will prompt you to provide your Azure credentials to log in.

Sign in with a managed identity

You can sign in with a managed identity. Managed identities are a feature of the Azure Active Directory. You can use the below PowerShell cmdlet to log in to the Azure PowerShell.

PS C:\WINDOWS\system32> Connect-AzAccount -Identity

Sign in with a Cloud Solution Provider (CSP)

In case your account is associated with multiple tenants or you are a Cloud Solution Provider (CSP), then you need to specify the tenant ID along with the PowerShell cmdlet. You can use the below PowerShell cmdlet to sign into the Azure PowerShell.

PS C:\WINDOWS\system32> Connect-AzAccount -Tenant '****-****-****-****’

Sign in with a service principal

You need to sign in with a service principal, use the -ServicePrincipal an argument along with the Connect-AzAccount PowerShell cmdlet. 

Password-based authentication

For the password-based authentication, you can use the below PowerShell script

$sp = New-AzADServicePrincipal -DisplayName ServicePrincipalName
$sp.secret | ConvertFrom-SecureString -AsPlainText

$cred = Get-Credential -UserName $sp.ApplicationId
Connect-AzAccount -ServicePrincipal -Credential $cred -Tenant $tenantId

Certificate-based authentication

You can also use the Certificate-based authentication using the below PowerShell cmdlet

PS C:\WINDOWS\system32> Connect-AzAccount -ServicePrincipal -ApplicationId $servicePrincipalId -Tenant $tenantId -CertificateThumbprint <thumbprint>

Install AzureRM PowerShell

Well, above we have discussed how to install the Azure Az module. Now let’s discuss How to Install AzureRM PowerShell. Follow the below steps to install the AzureRM module.

Sep-1: Open the PowerShell ISE using the Run as Administrator mode.

install microsoft azure powershell module

Step-2: Run the below PowerShell cmdlet to make sure you have the PowerShell Get-Module is installed on your local machine.

PS C:\WINDOWS\system32> Get-Module PowerShellGet -list | Select-Object Name,Version,Path
Install AzureRM PowerShell

Step-3: To install the AzureRM PowerShell module, run the below PowerShell cmdlet

PS C:\WINDOWS\system32> Install-Module -Name AzureRM
How to Install AzureRM PowerShell module

You can also specify the version of the PowerShell AzureRM module. You can use the below PowerShell cmdlet for the same.

PS C:\WINDOWS\system32> Install-Module -Name AzureRM -RequiredVersion 2.3.0
How to Install AzureRM PowerShell

You can also use the below PowerShell cmdlet to install the AzureRM module

Install-Module AzureRM -AllowClobber
azurerm modules install

Once, you will execute the above PowerShell cmdlet, then click on the Yes to All button to confirm the installation of the AzureRM module.

After you clicked on the Yes to All button, it will start the installation of the AzureRM module as shown below

How to Install AzureRM module PowerShell

Now, to make sure that the AzureRM module is installed successfully, you can run the below PowerShell cmdlet

Get-InstalledModule 
azurerm vs az

In which operating system, we can use Azure Powershell?

You can use Azure PowerShell in a list of operating systems like Windows 7 and the later versions, Mac OS, Linux, etc.

Install Azure CLI

You can check out my article on Install Azure CLI now.

You may also like following the below articles

Wrapping Up

Well, in this article, we have discussed How to install Azure PowerShell, Azure PowerShell module, Azure PowerShell, Cloud Shell, Installing the Azure PowerShell Module and we also discussed How to install Azure PowerShell module offline, Download Azure PowerShell MSI, Update the Azure PowerShell Module, Install AzureRM PowerShell and finally, we discussed Connect to Azure AD PowerShell. Hope you have enjoyed this article !!!