Automatically migrate PowerShell scripts from AzureRM to the Az PowerShell module
Artikel
In this article, you'll learn how to use the Az.Tools.Migration PowerShell module to automatically
upgrade your PowerShell scripts and script modules from AzureRM to the Az PowerShell module. For
additional migration options, see
Migrate Azure PowerShell from AzureRM to Az.
Varning
The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are
advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and
updates.
Although the AzureRM module may still function, it's no longer maintained or supported, placing
any continued use at the user's discretion and risk. Please refer to our
migration resources for guidance on transitioning to the Az module.
You use the New-AzUpgradeModulePlan cmdlet to generate an upgrade plan for migrating your
scripts and modules to the Az PowerShell module. This cmdlet doesn’t make any changes to your
existing scripts. Use the FilePath parameter for targeting a specific script or the
DirectoryPath parameter for targeting all scripts in a specific folder.
Anteckning
The New-AzUpgradeModulePlan cmdlet doesn't execute the plan, it only generates the upgrade steps.
The following example generates a plan for all the scripts in the C:\Scripts folder. The
OutVariable parameter is specified so the results are returned and simultaneously stored in a
variable named Plan.
PowerShell
# Generate an upgrade plan for all the scripts and module files in the specified folder and save it to a variable.New-AzUpgradeModulePlan -FromAzureRmVersion6.13.1 -ToAzVersion latest -DirectoryPath'C:\Scripts' -OutVariable Plan
As shown in the following output, the upgrade plan details the specific file and offset points that
require changes when moving from AzureRM to the Az PowerShell cmdlets.
Before performing the upgrade, you need to view the results of the plan for problems. The following
example returns a list of scripts and the items in those scripts that will prevent them from being
upgraded automatically.
PowerShell
# Filter plan results to only warnings and errors$Plan | Where-Object PlanResult -ne ReadyToUpgrade | Format-List
The items shown in the following output won't be upgraded automatically without manually correcting
the issues first.
Output
Order : 42
UpgradeType : CmdletParameter
PlanResult : ErrorParameterNotFound
PlanSeverity : Error
PlanResultReason : Parameter was not found in Get-AzResource or it's aliases.
SourceCommand : CommandReference
SourceCommandParameter : CommandReferenceParameter
Location : devtestlab-add-marketplace-image-to-lab.ps1:14:74
FullPath : C:\Scripts\devtestlab-add-marketplace-image-to-lab.ps1
StartOffset : 556
Original : ResourceNameEquals
Replacement :
Step 2: Perform the upgrade
Varning
There is no undo operation. Always ensure that you have a backup copy of your PowerShell scripts
and modules that you're attempting to upgrade.
After you’re satisfied with the plan, the upgrade is performed with the
Invoke-AzUpgradeModulePlan cmdlet. Specify SaveChangesToNewFiles for the
FileEditMode parameter value to prevent changes from being made to your original scripts. When
using this mode, the upgrade is performed by creating a copy of each script targeted with
_az_upgraded appended to the filenames.
Varning
The Invoke-AzUpgradeModulePlan cmdlet is destructive when the
-FileEditMode ModifyExistingFiles option is specified! It modifies your scripts and
functions in place according to the module upgrade plan generated by the
New-AzUpgradeModulePlan cmdlet. For the non-destructive option specify
-FileEditMode SaveChangesToNewFiles instead.
PowerShell
# Execute the automatic upgrade plan and save the results to a variable.Invoke-AzUpgradeModulePlan -Plan$Plan -FileEditMode SaveChangesToNewFiles -OutVariable Results
Källan för det här innehållet finns på GitHub, där du även kan skapa och granska ärenden och pull-begäranden. Se vår deltagarguide för mer information.
Feedback om Azure PowerShell
Azure PowerShell är ett öppen källkod projekt. Välj en länk för att ge feedback:
Lär dig hur du migrerar en arbetsbelastning som körs i Windows Server till en virtuell IaaS-dator (infrastruktur som en tjänst) och till Windows Server 2025 med hjälp av Migreringsverktyg för Windows Server eller Storage Migration Service.
Översikt över AzureRM PowerShell-modulens tillbakadragning, inklusive steg och verktyg för att migrera Azure PowerShell-skript från AzureRM till Az PowerShell-modulen.