How Migrate Azure PowerShell from AzureRM to Az

Andersonmorony
2 min readSep 8, 2022

--

This is a way to Automatically migrate PowerShell scripts from AzureRM to the Az PowerShell module

You’ll need it probably if want use power shell on Azure DevOps

Requirements

Install-Module -Name Az.Tools.Migration
  1. Save your script in some folder.
  2. open power shell as administration
  3. Execute this command
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion 8.0.0 -DirectoryPath 'C:\MYFOLDER' -OutVariable Plan

output:

Your code is ready to upgrade, can see in “planResult” column

4. Execute this command to complete the upgrade

Invoke-AzUpgradeModulePlan -Plan $Plan -FileEditMode SaveChangesToNewFiles -OutVariable Results

Output

Done! was create a new file with power shell code upgrade to AZ.

Code Before:

$resourceGoupName = "RG-TEST"
$resource = "myAPP/authsettings"
$resourceDestination = "myAPP-Development/authsettings"
# get the app settings from app1$resource = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGoupName -ResourceType Microsoft.Web/sites/config -ResourceName $resource -Action list -ApiVersion 2020-12-01 -Force# update the other app with $resource.PropertiesNew-AzureRmResource -PropertyObject $resource.Properties -ResourceGroupName $resourceGoupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceDestination -ApiVersion 2020-12-01 -Force

Code After upgrade:

$resourceGoupName = "RG-TEST"
$resource = "myAPP/authsettings"
$resourceDestination = "myAPP-Development/authsettings"
# get the app settings from app1$resource = Invoke-AzResourceAction -ResourceGroupName $resourceGoupName -ResourceType Microsoft.Web/sites/config -ResourceName $resource -Action list -ApiVersion 2020-12-01 -Force# update the other app with $resource.PropertiesNew-AzResource -Properties $resource.Properties -ResourceGroupName $resourceGoupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceDestination -ApiVersion 2020-12-01 -Force

--

--

Andersonmorony
Andersonmorony

Written by Andersonmorony

Azure, SharePoint, Power Plataforms, Nodejs and .Net Developer

No responses yet