Adding PowerShell commands for Azure

by Jul 29, 2020

To manage and automate your assets in the Azure cloud, you can easily install a free PowerShell module which comes with a wealth of new PowerShell commands:

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

On Windows PowerShell, it is not recommended to install the “Az” module when you already installed the older “AzureRM” module, so the code above checks whether the “AzureRM” module is present and downloads and installs the new “Az” module only when it is not present on Windows PowerShell.

The “Az” module consists of many nested modules, and they are all installed. This process can take a few minutes. Once the module is installed, you can take a look at all the new modules and the commands that come with them:

# listing all new commands
Get-Command -Module Az.*

# listing all new modules
Get-Module -Name Az.* -ListAvailable

The first step is to connect to your Azure account:

 
PS> Connect-AzAccount  
 

If you have more than one Azure subscription, you can choose the one to use like this:

 
Get-AzSubscription | Out-GridView -Title 'Subscription?' -OutputMode Single | Select-AzSubscription  
 

Once you are connected, you can start playing with the new commands. As a beginner, you should focus on commands with the verb “Get” so you don’t mess anything up:

# listing all Azure VMs
Get-AzVM

# listing all safe Get-* cmdlets
Get-Command -Verb Get -Module Az.*

To find out what you can do with the new Azure commands, visit the extensive online help in your browser:

Start-Process -FilePath https://docs.microsoft.com/en-us/powershell/azure/new-azureps-module-az 


Twitter This Tip! ReTweet this Tip!