AzureRM에서 Az PowerShell 모듈로 PowerShell 스크립트 자동 마이그레이션

이 문서에서는 Az.Tools.Migration PowerShell 모듈을 사용하여 PowerShell 스크립트 및 스크립트 모듈을 AzureRM에서 Az PowerShell 모듈로 자동으로 업그레이드하는 방법을 알아봅니다. 추가 마이그레이션 옵션은 AzureRM에서 Az로 Azure PowerShell 마이그레이션을 참조 하세요.

Warning

AzureRM PowerShell 모듈은 2024년 2월 29일부터 공식적으로 사용되지 않습니다. 사용자는 지속적인 지원 및 업데이트를 보장하기 위해 AzureRM에서 Az PowerShell 모듈로 마이그레이션하는 것이 좋습니다.

AzureRM 모듈은 여전히 작동할 수 있지만 더 이상 기본 또는 지원되지 않으므로 사용자의 재량에 따라 계속 사용할 수 있습니다. Az 모듈로 전환하는 방법에 대한 지침은 마이그레이션 리소스를 참조하세요.

요구 사항

  • 기존 PowerShell 스크립트를 최신 버전의 AzureRM PowerShell 모듈(6.13.1)로 업데이트합니다.

  • Az.Tools.Migration PowerShell 모듈을 설치합니다.

    Install-Module -Name Az.Tools.Migration
    

1단계: 업그레이드 계획 생성

New-AzUpgradeModulePlan cmdlet을 사용하여 스크립트 및 모듈을 Az PowerShell 모듈로 마이그레이션하기 위한 업그레이드 계획을 생성할 수 있습니다. 이 cmdlet은 기존 스크립트를 변경하지 않습니다. FilePath 특정 스크립트를 대상으로 지정하거나 특정 폴더의 DirectoryPath 모든 스크립트를 대상으로 지정하는 매개 변수를 사용합니다.

참고 항목

New-AzUpgradeModulePlan cmdlet은 계획을 실행하지 않고 업그레이드 단계만 생성합니다.

다음 예에서는 C:\Scripts 폴더에 있는 모든 스크립트에 대한 계획을 생성합니다. OutVariable 매개 변수는 결과가 반환되고 동시에 명명Plan된 변수에 저장되도록 지정됩니다.

# Generate an upgrade plan for all the scripts and module files in the specified folder and save it to a variable.
New-AzUpgradeModulePlan -FromAzureRmVersion 6.13.1 -ToAzVersion latest -DirectoryPath 'C:\Scripts' -OutVariable Plan

다음 출력과 같이 업그레이드 계획은 AzureRM에서 Az PowerShell cmdlet으로 이동할 때 변경이 필요한 특정 파일 및 오프셋 지점에 대해 자세히 설명합니다.

Order Location                                                   UpgradeType     PlanResult             Original
----- --------                                                   -----------     ----------             --------
1     compute-create-dockerhost.ps1:59:24                        CmdletParameter ReadyToUpgrade         ExtensionName
2     compute-create-dockerhost.ps1:59:1                         Cmdlet          ReadyToUpgrade         Set-AzureRmVM...
3     compute-create-dockerhost.ps1:54:1                         Cmdlet          ReadyToUpgrade         New-AzureRmVM
4     compute-create-dockerhost.ps1:51:1                         Cmdlet          ReadyToUpgrade         Add-AzureRmVM...
5     compute-create-dockerhost.ps1:47:1                         Cmdlet          ReadyToUpgrade         Add-AzureRmVM...
6     compute-create-dockerhost.ps1:46:1                         Cmdlet          ReadyToUpgrade         Set-AzureRmVM...
7     compute-create-dockerhost.ps1:45:1                         Cmdlet          ReadyToUpgrade         Set-AzureRmVM...
8     compute-create-dockerhost.ps1:44:13                        Cmdlet          ReadyToUpgrade         New-AzureRmVM...
9     compute-create-dockerhost.ps1:40:8                         Cmdlet          ReadyToUpgrade         New-AzureRmNe...
10    compute-create-dockerhost.ps1:36:8                         Cmdlet          ReadyToUpgrade         New-AzureRmNe...
11    compute-create-dockerhost.ps1:31:16                        Cmdlet          ReadyToUpgrade         New-AzureRmNe...
12    compute-create-dockerhost.ps1:26:15                        Cmdlet          ReadyToUpgrade         New-AzureRmNe...
13    compute-create-dockerhost.ps1:22:8                         Cmdlet          ReadyToUpgrade         New-AzureRmPu...
14    compute-create-dockerhost.ps1:18:9                         Cmdlet          ReadyToUpgrade         New-AzureRmVi...
15    compute-create-dockerhost.ps1:15:17                        Cmdlet          ReadyToUpgrade         New-AzureRmVi...
16    compute-create-dockerhost.ps1:12:1                         Cmdlet          ReadyToUpgrade         New-AzureRmRe...
17    compute-create-windowsvm-quick.ps1:18:3                    CmdletParameter ReadyToUpgrade         ImageName
18    compute-create-windowsvm-quick.ps1:14:1                    Cmdlet          ReadyToUpgrade         New-AzureRmVM
19    compute-create-windowsvm-quick.ps1:11:1                    Cmdlet          ReadyToUpgrade         New-AzureRmRe...
20    compute-create-wordpress-mysql.ps1:59:24                   CmdletParameter ReadyToUpgrade         ExtensionName
...

업그레이드를 수행하기 전에 문제의 계획 결과를 확인해야 합니다. 다음 예제에서는 스크립트 목록과 스크립트가 자동으로 업그레이드되지 않도록 하는 해당 스크립트의 항목을 반환합니다.

# Filter plan results to only warnings and errors
$Plan | Where-Object PlanResult -ne ReadyToUpgrade | Format-List

다음 출력에 표시된 항목은 문제를 먼저 수동으로 수정하지 않고 자동으로 업그레이드되지 않습니다.

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            :

2단계: 업그레이드 수행

주의

실행 취소 작업은 없습니다. 항상 업그레이드하려는 PowerShell 스크립트 및 모듈의 백업 복사본이 있는지 확인합니다.

계획에 만족하면 cmdlet을 사용하여 업그레이드가 Invoke-AzUpgradeModulePlan 수행됩니다. 원래 스크립트가 변경되지 않도록 하려면 FileEditMode 매개 변수 값에서 SaveChangesToNewFiles를 지정합니다. 이 모드를 사용하는 경우 파일 이름에 추가된 _az_upgraded 대상인 각 스크립트의 복사본을 만들어 업그레이드를 수행합니다.

Warning

Invoke-AzUpgradeModulePlan 옵션을 지정하면 cmdlet이 -FileEditMode ModifyExistingFiles 파괴적입니다. cmdlet에서 생성된 모듈 업그레이드 계획에 따라 스크립트와 함수를 New-AzUpgradeModulePlan 수정합니다. 비 파괴적 옵션의 경우 대신 지정합니다 -FileEditMode SaveChangesToNewFiles .

# Execute the automatic upgrade plan and save the results to a variable.
Invoke-AzUpgradeModulePlan -Plan $Plan -FileEditMode SaveChangesToNewFiles -OutVariable Results
Order Location                                                   UpgradeType     UpgradeResult    Original
----- --------                                                   -----------     -------------    --------
1     compute-create-dockerhost.ps1:59:24                        CmdletParameter UpgradeCompleted ExtensionName
2     compute-create-dockerhost.ps1:59:1                         Cmdlet          UpgradeCompleted Set-AzureRmVMExtens...
3     compute-create-dockerhost.ps1:54:1                         Cmdlet          UpgradeCompleted New-AzureRmVM
4     compute-create-dockerhost.ps1:51:1                         Cmdlet          UpgradeCompleted Add-AzureRmVMSshPub...
5     compute-create-dockerhost.ps1:47:1                         Cmdlet          UpgradeCompleted Add-AzureRmVMNetwor...
6     compute-create-dockerhost.ps1:46:1                         Cmdlet          UpgradeCompleted Set-AzureRmVMSource...
7     compute-create-dockerhost.ps1:45:1                         Cmdlet          UpgradeCompleted Set-AzureRmVMOperat...
8     compute-create-dockerhost.ps1:44:13                        Cmdlet          UpgradeCompleted New-AzureRmVMConfig
9     compute-create-dockerhost.ps1:40:8                         Cmdlet          UpgradeCompleted New-AzureRmNetworkI...
10    compute-create-dockerhost.ps1:36:8                         Cmdlet          UpgradeCompleted New-AzureRmNetworkS...
11    compute-create-dockerhost.ps1:31:16                        Cmdlet          UpgradeCompleted New-AzureRmNetworkS...
12    compute-create-dockerhost.ps1:26:15                        Cmdlet          UpgradeCompleted New-AzureRmNetworkS...
13    compute-create-dockerhost.ps1:22:8                         Cmdlet          UpgradeCompleted New-AzureRmPublicIp...
14    compute-create-dockerhost.ps1:18:9                         Cmdlet          UpgradeCompleted New-AzureRmVirtualN...
15    compute-create-dockerhost.ps1:15:17                        Cmdlet          UpgradeCompleted New-AzureRmVirtualN...
16    compute-create-dockerhost.ps1:12:1                         Cmdlet          UpgradeCompleted New-AzureRmResource...
17    compute-create-windowsvm-quick.ps1:18:3                    CmdletParameter UpgradeCompleted ImageName
18    compute-create-windowsvm-quick.ps1:14:1                    Cmdlet          UpgradeCompleted New-AzureRmVM
19    compute-create-windowsvm-quick.ps1:11:1                    Cmdlet          UpgradeCompleted New-AzureRmResource...
20    compute-create-wordpress-mysql.ps1:59:24                   CmdletParameter UpgradeCompleted ExtensionName
...

오류가 반환되면 다음 명령을 사용하여 오류 결과를 자세히 살펴볼 수 있습니다.

# Filter results to show only errors
$Results | Where-Object UpgradeResult -ne UpgradeCompleted | Format-List
Order                  : 42
UpgradeType            : CmdletParameter
UpgradeResult          : UnableToUpgrade
UpgradeSeverity        : Error
UpgradeResultReason    : 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            :

제한 사항

  • 파일 I/O 작업은 기본 인코딩을 사용합니다. 비정상적인 파일 인코딩 상황에서 문제가 발생할 수 있습니다.
  • Pester 단위 테스트 모의 문에 인수로 전달된 AzureRM cmdlet은 검색되지 않습니다.

문제를 보고하는 방법

azure-powershell-migration 리포지토리에서 GitHub 문제를 통해 Az.Tools.Migration PowerShell 모듈에 대한 피드백 및 문제를 보고합니다.

다음 단계

Az PowerShell 모듈에 대한 자세한 내용은 Azure PowerShell 설명서를 참조 하세요.