On Twitter, I recently asked if anyone was still using the AzureRM PowerShell module and what was keeping them from transitioning to the Az PowerShell module. One of the responses I received was due to the amount of work and time invested in scripts based on the AzureRM module.
The Az PowerShell module includes compatibility aliases for scripts written using the AzureRM PowerShell module. The compatibility aliases are enabled using the Enable-AzureRmAlias command. I decided to determine how compatible these so-called compatibility aliases are, at least from the standpoint of possibly missing commands altogether.
Since you can’t have both modules loaded at the same time in the same session, I decided to load the AzureRM module in Windows PowerShell 5.1 and the Az module in PowerShell 7.
First, I exported a list of all the commands in the AzureRM module to a CLI XML file.
Import-Module -Name AzureRM Get-Command -Module AzureRM.* | Export-Clixml -Path C:\tmp\azurerm.xml
After importing the Az PowerShell module into PowerShell 7, I stored the current aliases from the
session in a variable and then ran the
Import-Module -Name Az $PreAlias = Get-Alias Enable-AzureRmAlias
Next, I compared the aliases before and after running the
Enable-AzureRmAlias command and stored
the results in another CLI XML file.
Compare-Object -ReferenceObject $PreAlias -DifferenceObject (Get-Alias) -Property Name | Export-Clixml -Path C:\tmp\az.xml
I compared the commands from the AzureRM module to the compatibility aliases added from the Az module using the previously exported XML files. 159 commands exist in the AzureRM module that don’t exist as aliases when enabling AzureRM compatibility aliases in the Az module.
Compare-Object -ReferenceObject (Import-Clixml -Path C:\tmp\azurerm.xml) -DifferenceObject (Import-Clixml -Path C:\tmp\az.xml) -Property Name | Where-Object SideIndicator -eq '<='
I ran the same command again except this time exporting the results to another CLI XML file.
Compare-Object -ReferenceObject (Import-Clixml -Path C:\tmp\azurerm.xml) -DifferenceObject (Import-Clixml -Path C:\tmp\az.xml) -Property Name | Where-Object SideIndicator -eq '<=' | Export-Clixml -Path C:\tmp\azure-diff.xml
I switched back to Windows PowerShell since that’s where the AzureRM module is imported to determine what types of commands are missing. Based on the results, if you’re not currently following PowerShell best practices and using aliases from the AzureRM module in your PowerShell code, you’re out of luck with the compatibility aliases.
Import-Clixml -Path C:\tmp\azure-diff.xml | Select-Object -Property Name | Get-Command
The majority of the missing commands are aliases from the AzureRM module, but there are also a few cmdlets missing.
Import-Clixml -Path C:\tmp\azure-diff.xml | Get-Command | Group-Object -Property CommandType -NoElement
While your existing PowerShell code probably doesn’t use these commands, it’s something to be aware of.
Import-Clixml -Path C:\tmp\azure-diff.xml | Get-Command | Where-Object CommandType -eq Cmdlet | Sort-Object -Property Source, Name
If you are using any of the AzureRM aliases in your PowerShell code, one alternative is to use PSScriptAnalyzer to automatically update the aliases to the actual cmdlet names. Since the AzureRM compatibility aliases are aliased to the new cmdlets in the Az module, PSScriptAnalyzer could also be used to automatically update your existing code to the new cmdlet names in the Az module.