How Migrate Azure PowerShell from AzureRM to Az
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
- Update your existing PowerShell scripts to the latest version of the AzureRM PowerShell module (6.13.1).
- Install the Az.Tools.Migration PowerShell module.
Install-Module -Name Az.Tools.Migration
- Save your script in some folder.
- open power shell as administration
- 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