Azure

Installing and Connecting PowerShell Az Module with Microsoft Azure

A look at Installing and Connecting PowerShell Az Module with Microsoft Azure to see how to install the module migrate from AzureRM and connect to Azure

Interacting with Microsoft Azure is certainly achievable with the Azure portal, however, perhaps one of the huge advantages and features of cloud environment such as Microsoft Azure is the ability to interact programmatically with all aspects of the cloud. Microsoft’s PowerShell scripting language has gained huge adoption among administrators, engineers, and DevOps folks both on-premises as well as in the cloud. Working with Azure via PowerShell code is certainly a very powerful option for interacting with the Azure environment. As most know, Powershell has been undergoing a transformation from a Windows-only solution to a true cross-platform language that can be used on many different platforms. This has been made possible with PowerShell Core. Up until the end of 2018, Azure’s legacy PowerShell module (AzureRM) has not been cross-platform. However, the Azure team in December 2018 released the Azure “Az” PowerShell module that is the roadmap moving forward for interacting with Azure via PowerShell. In this post, we will take a look at installing and connecting PowerShell Az module with Microsoft Azure to see how the module can easily be installed and used for interacting with Azure environments.

What is Microsoft Azure PowerShell Az Module?

Azure PowerShell Az module is the way forward for PowerShell with Azure and those who currently have scripts written for AzureRM module for Azure need to begin migrating these over to using the Az module. There are some ways to get around having to make a hard switch at the moment from AzureRM to Az including using PowerShell Core for AZ, using AzureRM aliases in Az, and other means. However, the writing is certainly already on the wall that Az is the only way forward. In fact, only bug fixes will be released for the existing AzureRM module and new functionality will only be released for the Azure PowerShell Az module.

Many of the improvements with the Azure Az command come in the way of shorter commands, improved stability, and cross-platform support. At this point, it already offers feature parity with AzureRM, so customers are not losing any functionality migrating over to using the new module. It is based on the .NET Standard library which allows it to run on both PowerShell 5.x and PowerShell 6 which allows the cross-platform functionality.

Migrating from AzureRM PowerShell Module to Az

If customers have already uninstalled AzureRM module in favor of Az, they can run Az in “compatibility mode” to allow using existing scripts while working on updating those scripts to using the new syntax. An important consideration for the compatibility mode is to make sure that only the Az module is installed and AzureRM has been uninstalled.

You can check to see if you have the AzureRM module installed with the following command:

Get-InstalledModule -Name AzureRM -AllVersions

How do you uninstall the AzureRM PowerShell module?

Uninstall-Module -Name AzureRM

To enable the new compatibility mode, use the cmdlet:

Enable-AzureRmAlias

Installing and Connecting PowerShell Az Module with Microsoft Azure

The first thing we want to do is update the PowerShellGet module which contains cmdlets for discovering, installing, updating, and publishing PowerShell packages whcih contain PowerShell artifacts from the PowerShell gallery. The PowerShell gallery is the central repository for PowerShell content. It contains useful PowerShell modules containing PowerShell commands and DSC resources, powershell scripts, etc.

You can check for the currently installed version of PowerShellGet with the following command:

Get-Module -Name PowerShellGet -ListAvailable | Select-Object -Property Name, Version, Path

Getting-the-currently-installed-version-of-PowerShellGet-on-a-Windows-10-workstation
Getting the currently installed version of PowerShellGet on a Windows 10 workstation

To install the latest PowerShellGet module use the following command:

Install-Module PowerShellGet -Force

Installing-the-latest-version-fo-PowerShellGet
Installing the latest version fo PowerShellGet

Now, moving on to the actual installation of the Azure Powershell Az Module. To install the latest Az module, use the following command:

Install-Module -Name Az -AllowClobber

Installing-the-latest-Azure-Az-PowerShell-module
Installing the latest Azure Az PowerShell module

The package installation for the Az module proceeds.

The-Azure-Az-module-installation-proceeds
The Azure Az module installation proceeds

Once the module is loaded, import the module into the PowerShell session with the command:

Import-Module Az

Importing-the-Az-Module-in-the-PowerShell-session
Importing the Az Module in the PowerShell session

You can verify the module installation with the command:

Get-InstalledModule -Name Az -AllVersions

Once the module is installed and loaded into the PowerShell session, we can now connect to the Azure instance:

Connect-AzAccount

Connecting-to-a-Microsoft-Azure-account-with-the-Az-PowerShell-module
Connecting to a Microsoft Azure account with the Az PowerShell module

This will launch the normal Microsoft Azure portal login GUI screens, having you enter your Azure Portal email address, account type, and password.

Signing-in-as-normal-to-your-Microsoft-Azure-account
Signing in as normal to your Microsoft Azure account
Choosing-work-or-personal-account-type
Choosing work or personal account type
Entering-password-for-Azure-account
Entering password for Azure account

After entering credentials for the Azure portal, you should be connected to the Azure Portal via PowerShell. To verify, you can use the following cmdlet:

Get-AzureSubscription

Getting-subscription-details-with-the-Az-PowerShell-module
Getting subscription details with the Az PowerShell module

Azure PowerShell Resources

Wrapping Up

It is extremely easy to get started using PowerShell connected to Microsoft Azure public cloud. Installing and Connecting PowerShell Az Module with Microsoft Azure is the new way forward to utilize the newest functionality from a PowerShell modules perspective connected to Azure. As shown, this process is just a few steps including updating the PowershellGet module, uninstalling the AzureRM module (if installed and you want to use compatibility mode), and installing the Az module. After installation, you can simply connect to the Azure subscription via PowerShell. Next, we will take a look at some basic PowerShell Az commands to perform actions like creating VMs, interacting with them, etc. Stay tuned!

Subscribe to VirtualizationHowto via Email 🔔

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Brandon Lee

Brandon Lee is the Senior Writer, Engineer and owner at Virtualizationhowto.com and has over two decades of experience in Information Technology. Having worked for numerous Fortune 500 companies as well as in various industries, Brandon has extensive experience in various IT segments and is a strong advocate for open source technologies. Brandon holds many industry certifications, loves the outdoors and spending time with family.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.