本文档提供有关 AzureRM 6.x 与新 Az 模块版本 1.x 及更高版本之间的更改的详细信息。 目录表将帮助您浏览完整的迁移路径,包括特定模块的更改,这些更改可能会影响您的脚本。
有关从 AzureRM 迁移到 Az 的一般建议,请参阅 开始从 AzureRM 迁移到 Az。
重要
Az 1.0.0 和 Az 2.0.0 之间也有重大更改。 按照本指南将 AzureRM 更新到 Az 后,请参阅 Az 2.0.0 中断性变更 ,了解是否需要进行其他更改。
目录
- 常规重大更改
- 模块重大更改
- Az.ApiManagement (以前为 AzureRM.ApiManagement)
- Az.Billing(以前是 AzureRM.Billing、AzureRM.Consumption 和 AzureRM.UsageAggregates)
- Az.CognitiveServices (以前为 AzureRM.CognitiveServices)
- Az.Compute (以前为 AzureRM.Compute)
- Az.DataFactory (以前为 AzureRM.DataFactories 和 AzureRM.DataFactoryV2)
- Az.DataLakeAnalytics (以前为 AzureRM.DataLakeAnalytics)
- Az.DataLakeStore (以前为 AzureRM.DataLakeStore)
- Az.KeyVault (以前为 AzureRM.KeyVault)
- Az.Media (以前为 AzureRM.Media)
- Az.Monitor (以前为 AzureRM.Insights)
- Az.Network (以前为 AzureRM.Network)
- Az.OperationalInsights (以前为 AzureRM.OperationalInsights)
- Az.RecoveryServices(以前为 AzureRM.RecoveryServices、AzureRM.RecoveryServices.Backup 和 AzureRM.RecoveryServices.SiteRecovery)
- Az.Resources (以前为 AzureRM.Resources)
- Az.ServiceFabric (以前为 AzureRM.ServiceFabric)
- Az.Sql(以前为 AzureRM.Sql)
- Az.Storage(以前是 Azure.Storage 和 AzureRM.Storage)
- Az.Websites (以前为 AzureRM.Websites)
常规重大更改
此部分详述 Az 模块重新设计中的总体重大变更。
Cmdlet 名词前缀更改
在 AzureRM 模块中,cmdlet 使用 AzureRM
或 Azure
作为名词前缀。 Az 简化了 cmdlet 名称并规范化,以便所有 cmdlet 都使用“Az”作为其 cmdlet 名词前缀。 例如:
Get-AzureRMVM
Get-AzureKeyVaultSecret
已更改为:
Get-AzVM
Get-AzKeyVaultSecret
为了简化对这些新 cmdlet 名称的转换,Az 引入了两个新的 cmdlet,Enable-AzureRmAlias,Disable-AzureRmAlias。 Enable-AzureRmAlias
为 AzureRM 中较旧的 cmdlet 名称创建别名,这些名称映射到较新的 Az cmdlet 名称。 将 -Scope
参数与 Enable-AzureRmAlias
结合使用,可以选择启用别名的位置。
例如,AzureRM 中的以下脚本:
#Requires -Modules AzureRM.Storage
Get-AzureRmStorageAccount | Get-AzureStorageContainer | Get-AzureStorageBlob
可以通过使用 Enable-AzureRmAlias
进行最少的更改来运行:
#Requires -Modules Az.Storage
Enable-AzureRmAlias -Scope Process
Get-AzureRmStorageAccount | Get-AzureStorageContainer | Get-AzureStorageBlob
运行 Enable-AzureRmAlias -Scope CurrentUser
将启用打开的所有 PowerShell 会话的别名,以便在执行此 cmdlet 之后,无需更改如下所示的脚本:
Get-AzureRmStorageAccount | Get-AzureStorageContainer | Get-AzureStorageBlob
若要获得有关别名 cmdlet 用法的完整详细信息,请查看 Enable-AzureRmAlias 参考。
准备好禁用别名时,Disable-AzureRmAlias
删除创建的别名。 有关完整详细信息,请参阅 Disable-AzureRmAlias 参考。
重要
禁用别名时,请确保在别名启用过的所有范围内将其禁用。
模块名称更改
模块名称已从 AzureRM.*
更改为 Az.*
,但以下模块除外:
AzureRM 模块 | Az 模块 |
---|---|
Azure.Storage | Az.Storage |
Azure.AnalysisServices(分析服务) | Az.AnalysisServices |
AzureRM.Profile | Az.Accounts |
AzureRM.Insights | Az.Monitor |
AzureRM.DataFactories | Az.DataFactory |
AzureRM.DataFactoryV2 | Az.DataFactory |
AzureRM.RecoveryServices.Backup | Az.RecoveryServices |
AzureRM.RecoveryServices.SiteRecovery | Az.RecoveryServices |
AzureRM.Tags | Az.Resources |
AzureRM.MachineLearningCompute | Az.MachineLearning |
AzureRM.UsageAggregates | Az.Billing |
AzureRM.Consumption | Az.Billing |
模块名称中的更改意味着需要更改使用 #Requires
或 Import-Module
加载特定模块的任何脚本,才能改用新模块。 对于其中的 cmdlet 后缀尚未更改的模块,这意味着,虽然模块名称已更改,但指示操作空间的后缀尚未更改。
迁移 #Requires 和 Import-Module 语句
必须更新那些使用 #Requires
或 Import-Module
声明对 AzureRM 模块依赖的脚本,以便使用新的模块名称。 例如:
#Requires -Module AzureRM.Compute
应更改为:
#Requires -Module Az.Compute
对于 Import-Module
:
Import-Module -Name AzureRM.Compute
应更改为:
Import-Module -Name Az.Compute
迁移完全限定的 Cmdlet 调用
使用模块限定的 cmdlet 调用的脚本,例如:
AzureRM.Compute\Get-AzureRmVM
必须更改以使用新的模块和命令行小程序名称:
Az.Compute\Get-AzVM
迁移模块清单依赖关系
通过模块清单(.psd1)文件表达对 AzureRM 模块的依赖项的模块将需要在其 RequiredModules
部分中更新模块名称:
RequiredModules = @(@{ModuleName="AzureRM.Profile"; ModuleVersion="5.8.2"})
必须更改为:
RequiredModules = @(@{ModuleName="Az.Profile"; ModuleVersion="1.0.0"})
已删除的模块
已删除以下模块:
AzureRM.Backup
AzureRM.Compute.ManagedService
AzureRM.Scheduler
这些服务所用的工具不再受到主动支持。 建议客户在方便后立即迁移到替代服务。
Windows PowerShell 5.1 和 .NET 4.7.2
将 Az 与 PowerShell 5.1 for Windows 配合使用需要安装 .NET Framework 4.7.2。 使用 PowerShell Core 6.x 或更高版本不需要 .NET Framework。
临时移除用户使用 PSCredential 的登录功能
由于 .NET Standard 的身份验证流发生更改,我们暂时通过 PSCredential 删除用户登录名。 此功能将在 2019 年 1 月 15 日版本的 PowerShell 5.1 for Windows 中重新引入。 此 GitHub 问题中详细讨论了这方面的内容。
改为使用默认设备代码登录,而不使用 Web 浏览器提示。
由于 .NET Standard 的身份验证流发生更改,我们在交互式登录期间使用设备登录作为默认登录流。 对于 Windows 的 PowerShell 5.1,基于网络浏览器的登录将在 2019 年 1 月 15 日发布的版本中重新引入,并作为默认方式。 届时,用户将能够使用切换参数选择设备登录。
模块中断性变更
此部分详述单个模块和 cmdlet 的具体重大更改。
Az.ApiManagement (以前为 AzureRM.ApiManagement)
- 删除了以下 cmdlet:
- New-AzureRmApiManagementHostnameConfiguration
- Set-AzureRmApiManagementHostnames
- Update-AzureRmApiManagementDeployment
- Import-AzureRmApiManagementHostnameCertificate
- 改用 Set-AzApiManagement cmdlet 设置这些属性
- 删除了以下属性:
- 从
PortalHostnameConfiguration
中删除了类型ProxyHostnameConfiguration
的属性ManagementHostnameConfiguration
、ScmHostnameConfiguration
、PsApiManagementHostnameConfiguration
和PsApiManagementContext
。 请改用PortalCustomHostnameConfiguration
类型的ProxyCustomHostnameConfiguration
、ManagementCustomHostnameConfiguration
、ScmCustomHostnameConfiguration
和PsApiManagementCustomHostNameConfiguration
。 - 从 PsApiManagementContext 中删除了属性
StaticIPs
。 该属性已拆分为PublicIPAddresses
和PrivateIPAddresses
。 - 从 New-AzureApiManagementVirtualNetwork cmdlet 中删除了所需的属性
Location
。
- 从
Az.Billing(以前是 AzureRM.Billing、AzureRM.Consumption 和 AzureRM.UsageAggregates)
InvoiceName
参数已从Get-AzConsumptionUsageDetail
cmdlet 中删除。 脚本需要使用发票的其他标识参数。
Az.CognitiveServices (以前为 AzureRM.CognitiveServices)
- 从
GetSkusWithAccountParamSetName
cmdlet 中删除了Get-AzCognitiveServicesAccountSkus
参数集。 必须按帐户类型和位置获取 SKU,而不是使用 ResourceGroupName 和帐户名称。
Az.Compute (以前为 AzureRM.Compute)
IdentityIds
从Identity
属性中删除,该属性属于PSVirtualMachine
和PSVirtualMachineScaleSet
对象,脚本不应再使用此字段的值来做出处理决策。InstanceView
对象的PSVirtualMachineScaleSetVM
属性的类型从VirtualMachineInstanceView
更改为VirtualMachineScaleSetVMInstanceView
- 从
AutoOSUpgradePolicy
属性中删除了AutomaticOSUpgrade
和UpgradePolicy
属性 Sku
对象中PSSnapshotUpdate
属性的类型从DiskSku
更改为SnapshotSku
VmScaleSetVMParameterSet
从Add-AzVMDataDisk
cmdlet 中删除,无法再单独向 ScaleSet VM 添加数据磁盘。
Az.DataFactory (以前为 AzureRM.DataFactories 和 AzureRM.DataFactoryV2)
GatewayName
参数在New-AzDataFactoryEncryptValue
cmdlet 中变为必需参数- 删除了
New-AzDataFactoryGatewayKey
cmdlet - 从
LinkedServiceName
cmdlet 中删除Get-AzDataFactoryV2ActivityRun
参数,脚本不应再使用此字段的值来做出处理决策。
Az.DataLakeAnalytics (以前为 AzureRM.DataLakeAnalytics)
- 删除了已弃用的 cmdlet:
New-AzDataLakeAnalyticsCatalogSecret
、Remove-AzDataLakeAnalyticsCatalogSecret
和Set-AzDataLakeAnalyticsCatalogSecret
Az.DataLakeStore (以前为 AzureRM.DataLakeStore)
以下 cmdlet 已将
Encoding
参数的类型从FileSystemCmdletProviderEncoding
更改为System.Text.Encoding
。 此更改将删除编码值String
和Oem
。 所有其他以前的编码值保持不变。- New-AzureRmDataLakeStoreItem
- Add-AzureRmDataLakeStoreItemContent
- Get-AzureRmDataLakeStoreItemContent
从
Tags
和New-AzDataLakeStoreAccount
cmdlet 中删除了弃用的Set-AzDataLakeStoreAccount
属性别名使用以下内容的脚本
New-AzureRMDataLakeStoreAccount -Tags @{TagName="TagValue"}
应更改为
New-AzDataLakeStoreAccount -Tag @{TagName="TagValue"}
从
Identity
对象中删除了已弃用的属性EncryptionState
、EncryptionProvisioningState
、EncryptionConfig
、FirewallState
、FirewallRules
、VirtualNetworkRules
、TrustedIdProviderState
、TrustedIdProviders
、DefaultGroup
、NewTier
、CurrentTier
、FirewallAllowAzureIps
、PSDataLakeStoreAccountBasic
。 使用PSDatalakeStoreAccount
返回结果Get-AzDataLakeStoreAccount
的任何脚本都不应引用这些属性。
Az.KeyVault (以前为 AzureRM.KeyVault)
PurgeDisabled
属性已从PSKeyVaultKeyAttributes
、PSKeyVaultKeyIdentityItem
和PSKeyVaultSecretAttributes
对象中删除,脚本不应再引用PurgeDisabled
属性来做出处理决策。
Az.Media (以前为 AzureRM.Media)
从
Tags
cmdlet 中删除了弃用的New-AzMediaService
属性别名。使用以下内容的脚本New-AzureRMMediaService -Tags @{TagName="TagValue"}
应更改为
New-AzMediaService -Tag @{TagName="TagValue"}
Az.Monitor (以前为 AzureRM.Insights)
从
Categories
cmdlet 中删除了复数名称Timegrains
和Set-AzDiagnosticSetting
参数并将其替换为单数参数名称。使用以下内容的脚本Set-AzureRmDiagnosticSetting -Timegrains PT1M -Categories Category1, Category2
应更改为
Set-AzDiagnosticSetting -Timegrain PT1M -Category Category1, Category2
Az.Network (以前为 AzureRM.Network)
- 从
ResourceId
cmdlet 中删除了弃用的Get-AzServiceEndpointPolicyDefinition
参数 - 从
EnableVmProtection
对象中删除了弃用的PSVirtualNetwork
属性 - 已删除已弃用的
Set-AzVirtualNetworkGatewayVpnClientConfig
cmdlet
脚本不应再根据这些字段的值做出处理决策。
Az.OperationalInsights (以前为 AzureRM.OperationalInsights)
删除了默认
Get-AzOperationalInsightsDataSource
参数集,并ByWorkspaceNameByKind
成为默认参数集使用以下内容列出了数据源的脚本
Get-AzureRmOperationalInsightsDataSource
应当更改为指定一个种类
Get-AzOperationalInsightsDataSource -Kind AzureActivityLog
Az.RecoveryServices(以前为 AzureRM.RecoveryServices、AzureRM.RecoveryServices.Backup 和 AzureRM.RecoveryServices.SiteRecovery)
- 从
Encryption
cmdlet 中删除了New/Set-AzRecoveryServicesAsrPolicy
参数 - 通过
TargetStorageAccountName
cmdlet 执行托管磁盘还原时,现在必须提供Restore-AzRecoveryServicesBackupItem
参数 - 在
StorageAccountName
cmdlet 中已删除StorageAccountResourceGroupName
和Restore-AzRecoveryServicesBackupItem
参数 - 在
Name
cmdlet 中删除了Get-AzRecoveryServicesBackupContainer
参数
Az.Resources (以前为 AzureRM.Resources)
从
Sku
cmdlet 中删除了New/Set-AzPolicyAssignment
参数从
Password
和New-AzADServicePrincipal
cmdlet 中删除了New-AzADSpCredential
参数。密码将自动生成,提供了密码的脚本:New-AzAdSpCredential -ObjectId 00001111-aaaa-2222-bbbb-3333cccc4444 -Password $secPassword
应更改以从输出中检索密码:
$credential = New-AzAdSpCredential -ObjectId 00001111-aaaa-2222-bbbb-3333cccc4444 $secPassword = $credential.Secret
Az.ServiceFabric (以前为 AzureRM.ServiceFabric)
- 已更改以下 cmdlet 返回类型:
- 类型为
ServiceTypeHealthPolicies
的属性ApplicationHealthPolicy
已被删除。 - 类型为
ApplicationHealthPolicies
的属性ClusterUpgradeDeltaHealthPolicy
已被删除。 - 类型为
OverrideUserUpgradePolicy
的属性ClusterUpgradePolicy
已被删除。 - 这些更改会影响以下命令行工具(cmdlet):
- Add-AzServiceFabricClientCertificate
- Add-AzServiceFabricClusterCertificate
- Add-AzServiceFabricNode
- Add-AzServiceFabricNodeType
- Get-AzServiceFabricCluster
- Remove-AzServiceFabricClientCertificate
- Remove-AzServiceFabricClusterCertificate
- Remove-AzServiceFabricNode
- Remove-AzServiceFabricNodeType
- Remove-AzServiceFabricSetting
- Set-AzServiceFabricSetting
- Set-AzServiceFabricUpgradeType
- Update-AzServiceFabricDurability
- Update-AzServiceFabricReliability
- 类型为
Az.Sql(以前为 AzureRM.Sql)
- 从
State
cmdlet 中删除了ResourceId
和Set-AzSqlDatabaseBackupLongTermRetentionPolicy
参数 - 删除了弃用的 cmdlet:
Get/Set-AzSqlServerBackupLongTermRetentionVault
、、Get/Start/Stop-AzSqlServerUpgrade
、Get/Set-AzSqlDatabaseAuditingPolicy
Get/Set-AzSqlServerAuditingPolicy
、、Remove-AzSqlDatabaseAuditing
Remove-AzSqlServerAuditing
- 从
Current
cmdlet 中删除了已弃用的参数Get-AzSqlDatabaseBackupLongTermRetentionPolicy
- 从
DatabaseName
cmdlet 中删除了已弃用的参数Get-AzSqlServerServiceObjective
- 从
PrivilegedLogin
cmdlet 中删除了已弃用的参数Set-AzSqlDatabaseDataMaskingPolicy
Az.Storage(以前是 Azure.Storage 和 AzureRM.Storage)
- 为了支持创建仅包含存储帐户名称的 Oauth 存储上下文,默认参数集已更改为
OAuthParameterSet
- 示例:
$ctx = New-AzureStorageContext -StorageAccountName $accountName
- 示例:
Location
参数在Get-AzStorageUsage
cmdlet 中变为必需参数- 存储 API 方法现在使用基于任务的异步模式(TAP),而不是同步 API 调用。 以下示例演示了新的异步命令:
Blob 快照
AzureRM:
$b = Get-AzureStorageBlob -Container $containerName -Blob $blobName -Context $ctx
$b.ICloudBlob.Snapshot()
Az:
$b = Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx
$task = $b.ICloudBlob.SnapshotAsync()
$task.Wait()
$snapshot = $task.Result
共享快照
AzureRM:
$Share = Get-AzureStorageShare -Name $containerName -Context $ctx
$snapshot = $Share.Snapshot()
Az:
$Share = Get-AzStorageShare -Name $containerName -Context $ctx
$task = $Share.SnapshotAsync()
$task.Wait()
$snapshot = $task.Result
撤消删除软删除的 Blob
AzureRM:
$b = Get-AzureStorageBlob -Container $containerName -Blob $blobName -IncludeDeleted -Context $ctx
$b.ICloudBlob.Undelete()
Az:
$b = Get-AzStorageBlob -Container $containerName -Blob $blobName -IncludeDeleted -Context $ctx
$task = $b.ICloudBlob.UndeleteAsync()
$task.Wait()
设置 Blob 层
AzureRM:
$blockBlob = Get-AzureStorageBlob -Container $containerName -Blob $blockBlobName -Context $ctx
$blockBlob.ICloudBlob.SetStandardBlobTier("hot")
$pageBlob = Get-AzureStorageBlob -Container $containerName -Blob $pageBlobName -Context $ctx
$pageBlob.ICloudBlob.SetPremiumBlobTier("P4")
Az:
$blockBlob = Get-AzStorageBlob -Container $containerName -Blob $blockBlobName -Context $ctx
$task = $blockBlob.ICloudBlob.SetStandardBlobTierAsync("hot")
$task.Wait()
$pageBlob = Get-AzStorageBlob -Container $containerName -Blob $pageBlobName -Context $ctx
$task = $pageBlob.ICloudBlob.SetPremiumBlobTierAsync("P4")
$task.Wait()
Az.Websites (以前为 AzureRM.Websites)
- 从
PSAppServicePlan
、PSCertificate
、PSCloningInfo
和PSSite
对象中删除了弃用的属性