Azure – Migrate your AzureRM scripts to Az PowerShell

As you know, you have multiple ways to manage your Azure environment; through the portal (, Cloud Shell (, Azure Cli, PowerShell modules…

Talking about the PowerShell module, you are probably aware that the AzureRM PowerShell modules are outdated (but still supported – for now) and have been replaced by the Az PowerShell modules.

That said, there are still lot of scripts out there still using this ‘old’ AzureRM modules.

Well, to help you migrating from AzureRM to Az modules, Microsoft has released an Az.Tools.Migration module to help you identify the scripts which can be migrated and then do the migration for you.

To take advantage of this AzureRM to Az Migration Toolkit, you need to:

  • Upgrade your AzureRM PowerShell modules to the latest version (6.13.1)using the commands

Update-Module -Name AzureRM -RequiredVersion 6.13.1

  • Then install the migration toolkit using the command

Install-Module -Name Az.Tools.Migration

image  image

Once the above steps have been completed, you can now start to generate your upgrade plan by using the New-AzUpgradeModulePlan command

New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 4.6.1 –DirectoryPath <location of your scripts> -OutVariable Plan (or any other variable name)

NOTE the Az version 4.6.1 is the latest available at the time of writing this post; in the future you will be able to update this version to use the latest one available at the time you run the command

image  image

You can review the results by exportin the content of the Plan variable.

You can also filter the results to review the script(s) with upgrade issues using the command

$Plan | Where-Object PlanResult -ne ReadyToUpgrade | Format-List


Once you have reviewed the results and isolated/updated the problematic script(s), you can now run the upgrade process using the command

NOTE if you have decided to isolate the problematic script(s) you will need to re run the upgrade plan command

Invoke-AzUpgradeModulePlan -Plan $Plan -FileEditMode SaveChangesToNewFiles -OutVariable Results (or any variable name)

image  image

Then you can review the upgrade results using the Results variable

$Results | Format-List


Your scripts are not updated; the upgrade process makes a copy of your script while updating the code; the file name is appended with _az_upgraded


Et voila, your AzureRM scripts are now migrated to use the Az module.

Leave a Comment

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

The reCAPTCHA verification period has expired. Please reload the page.