I’ve written quite a bit on using PowerShell to deploy and manage Windows Server virtual machines and other resources in the Azure cloud for Petri. But since those articles were published a lot has changed. Not only do we now have PowerShell Core, but Microsoft will no longer be adding features to Windows PowerShell, although it will still be supported. PowerShell Core is based on the .NET Core Framework, which means it also runs on Linux and MacOS. And if you want to start using PowerShell Core it can run side-by-side with Windows PowerShell on the same device.
For more information on PowerShell Core, see PowerShell Core 6.0 and Why Windows PowerShell Is No Longer Being Developed and 5 Things to Know About PowerShell Core on Windows on Petri.
The new open source Az module for PowerShell is cross-platform and replaces AzureRM, which Microsoft will continue to support. Az was released December 18th and Microsoft says that it will be updated twice a month, starting in the middle of January. New features for this release include:
The Az module can be installed from the PowerShell Gallery and it works in Windows PowerShell 5.1, PowerShell Core 6.0, and PowerShell Core 6.1. It’s possible to have the AzureRM and Az modules installed at the same time providing that you don’t enable aliases. If you are using Azure Cloud Shell, the Az module is now installed by default.
To install the Az module with global scope, run the Install-Module cmdlet as shown below in an elevated PowerShell window.
Install-Module -Name Az -AllowClobber
If you don’t have administrator rights or want to install for user scope only, add the -Scope parameter as shown here:
Install-Module -Name Az -AllowClobber -Scope CurrentUser
Once the Az module is installed, you can connect to your Azure subscription using the Connect-AzAccount cmdlet. This release doesn’t support user login with PSCredential, but the next version will support it for Windows PowerShell 5.1 only. Microsoft recommends signing in with a Service Principal when authenticating from a script. You can find more information about signing in with Service Principals on Microsoft’s website here.
To update the module, run Update-Module. Older versions of the module are not uninstalled but if you have more than one version of Az, by default module autoload and Import-Module load the latest version.
Update-Module -Name Az
To check which versions of the module you have installed, use Get-Module:
Get-Module -Name *Az.* -ListAvailable
For the purposes of backwards compatibility, you can enable aliases to use the new Az module to run scripts that were designed for use with AzureRM. The only condition is that if you enable aliases, you must remove the AzureRM module. The command below enables aliases for all modules for the current user.
Enable-AzureRmAlias -Scope CurrentUser
The -Scope parameter has three possible values: Process, CurrentUser, and LocalMachine. You can disable aliases using Disable-AzureRmAlias.