Automatically migrate PowerShell scripts from AzureRM to the Az PowerShell module
Artículo
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.
Advertencia
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.
Nota
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
Precaución
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.
Advertencia
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
El origen de este contenido se puede encontrar en GitHub, donde también puede crear y revisar problemas y solicitudes de incorporación de cambios. Para más información, consulte nuestra guía para colaboradores.
Comentarios de Azure PowerShell
Azure PowerShell es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios:
Obtenga información sobre cómo migrar una carga de trabajo que se ejecute en Windows Server a una máquina virtual (VM) de infraestructura como servicio (IaaS) y a Windows Server 2025 mediante el servicio de migración de almacenamiento o las herramientas de migración de Windows Server.
Como administrador híbrido de Windows Server, integra los entornos de Windows Server con servicios de Azure y administra Windows Server en redes locales.
Información general sobre la retirada del módulo De PowerShell de AzureRM, incluidos los pasos y las herramientas para migrar scripts de Azure PowerShell desde AzureRM al módulo Az PowerShell.
Información general sobre el módulo de PowerShell Az.Tools.Migration desarrollado y mantenido por el equipo de Azure PowerShell, pero no forma parte del módulo Az PowerShell.