Az 1.0.0 的重大變更

本檔提供有關 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 模組重新設計的一般重大變更。

Cmdlet 名詞前置詞變更

在 AzureRM 模組中,Cmdlet 會使用 AzureRMAzure 作為名詞前置詞。 Az 會簡化並正規化 Cmdlet 名稱,讓所有 Cmdlet 都使用 『Az』 作為其 Cmdlet 名詞前置詞。 例如:

Get-AzureRMVM
Get-AzureKeyVaultSecret

已變更為:

Get-AzVM
Get-AzKeyVaultSecret

為了簡化轉換至這些新的 Cmdlet 名稱,Az 引進了兩個新的 Cmdlet :Enable-AzureRmAliasDisable-AzureRmAliasEnable-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

模組名稱中的變更表示任何使用 #RequiresImport-Module 載入特定模組的腳本都必須變更,才能改用新的模組。 對於 Cmdlet 後綴未變更的模組,這表示雖然模組名稱已變更,但表示作業空間的後綴沒有

移轉 #Requires 和 Import-Module 語句

您必須更新使用 #RequiresImport-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

必須變更才能使用新的模組和 Cmdlet 名稱:

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 移除使用者登入。 此功能將會在適用於 Windows 的 PowerShell 5.1 的 2019/15 版本中重新推出。 這會在此 GitHub 問題中 詳細討論。

默認裝置程式代碼登入,而不是網頁瀏覽器提示

由於 .NET Standard 的驗證流程變更,我們會在互動式登入期間使用裝置登入作為默認登入流程。 在 2019/15/15 版本中,將會針對 Windows 的 PowerShell 5.1 重新導入網頁瀏覽器型登入。 屆時,用戶將能夠使用 Switch 參數來選擇裝置登入。

模組重大變更

本節詳細說明個別模組和 Cmdlet 的特定重大變更。

Az.ApiManagement (先前是 AzureRM.ApiManagement)

  • 已移除下列 Cmdlet:
    • New-AzureRmApiManagementHostnameConfiguration
    • Set-AzureRmApiManagementHostnames
    • Update-AzureRmApiManagementDeployment
    • Import-AzureRmApiManagementHostnameCertificate
    • 請改用 Set-AzApiManagement Cmdlet 來設定這些屬性
  • 已移除下列屬性:
    • 已從 中移除 類型的屬性 PortalHostnameConfigurationPsApiManagementHostnameConfigurationProxyHostnameConfigurationManagementHostnameConfigurationScmHostnameConfigurationPsApiManagementContext 請改用 PortalCustomHostnameConfiguration型態PsApiManagementCustomHostNameConfiguration為的、 ProxyCustomHostnameConfigurationManagementCustomHostnameConfigurationScmCustomHostnameConfiguration
    • 已從 PsApiManagementContext 移除屬性 StaticIPs 。 屬性已分割成 PublicIPAddressesPrivateIPAddresses
    • 已從 New-AzureApiManagementVirtualNetwork Cmdlet 中移除必要的屬性 Location

Az.Billing (先前是 AzureRM.Billing、AzureRM.Consumption 和 AzureRM.UsageAggregates)

  • 參數 InvoiceName 已從 Get-AzConsumptionUsageDetail Cmdlet 中移除。 腳本必須使用發票的其他身分識別參數。

Az.CognitiveServices (先前是 AzureRM.CognitiveServices)

  • 已從 Get-AzCognitiveServicesAccountSkus Cmdlet 移除GetSkusWithAccountParamSetName參數集。 您必須依帳戶類型和位置取得 Sku,而不是使用 ResourceGroupName 和帳戶名稱。

Az.Compute (先前是 AzureRM.Compute)

  • IdentityIds 已從 Identity 中的 PSVirtualMachine 屬性移除 ,而且 PSVirtualMachineScaleSet 腳本不應再使用此字段的值來進行處理決策。
  • 對象的屬性PSVirtualMachineScaleSetVM類型InstanceView會從 VirtualMachineInstanceView 變更為VirtualMachineScaleSetVMInstanceView
  • AutoOSUpgradePolicyAutomaticOSUpgrade 屬性會從 UpgradePolicy 屬性中移除
  • 物件中的PSSnapshotUpdate屬性類型Sku已從 DiskSku 變更為SnapshotSku
  • VmScaleSetVMParameterSet 已從 Add-AzVMDataDisk Cmdlet 中移除,您無法再個別將數據磁碟新增至 ScaleSet VM。

Az.DataFactory (先前是 AzureRM.DataFactories 和 AzureRM.DataFactoryV2)

  • Cmdlet GatewayName 中的 New-AzDataFactoryEncryptValue 參數已變成必要參數
  • 已移除 New-AzDataFactoryGatewayKey Cmdlet
  • 已從 Get-AzDataFactoryV2ActivityRun Cmdlet 腳本移除LinkedServiceName的參數不應再使用此欄位的值來進行處理決策。

Az.DataLakeAnalytics (先前是 AzureRM.DataLakeAnalytics)

  • 已移除已被取代的 Cmdlet: New-AzDataLakeAnalyticsCatalogSecretRemove-AzDataLakeAnalyticsCatalogSecret、 和 Set-AzDataLakeAnalyticsCatalogSecret

Az.DataLakeStore (先前是 AzureRM.DataLakeStore)

  • 下列 Cmdlet 已將 Encoding 參數從 類型 FileSystemCmdletProviderEncoding 變更為 System.Text.Encoding。 這項變更會移除編碼值 StringOem。 所有其他先前的編碼值都會維持不變。

    • New-AzureRmDataLakeStoreItem
    • Add-AzureRmDataLakeStoreItemContent
    • Get-AzureRmDataLakeStoreItemContent
  • 已從 New-AzDataLakeStoreAccountSet-AzDataLakeStoreAccount Cmdlet 移除已被Tags取代的屬性別名

    使用的腳本

    New-AzureRMDataLakeStoreAccount -Tags @{TagName="TagValue"}
    

    應變更為

    New-AzDataLakeStoreAccount -Tag @{TagName="TagValue"}
    
  • 已從物件中移除已被取代的屬性IdentityEncryptionStateEncryptionConfigTrustedIdProviderStateNewTierPSDataLakeStoreAccountBasicVirtualNetworkRulesCurrentTierDefaultGroupTrustedIdProvidersFirewallAllowAzureIpsEncryptionProvisioningStateFirewallStateFirewallRules 任何使用 所Get-AzDataLakeStoreAccount傳回的 PSDatalakeStoreAccount 腳本都不應該參考這些屬性。

Az.KeyVault (先前是 AzureRM.KeyVault)

  • 屬性 PurgeDisabled 已從 PSKeyVaultKeyAttributesPSKeyVaultKeyIdentityItemPSKeyVaultSecretAttributes 物件中移除腳本不應再參考 PurgeDisabled 屬性來進行處理決策。

Az.Media (先前是 AzureRM.Media)

  • 使用 從 New-AzMediaService Cmdlet 腳本中移除已被Tags取代的屬性別名

    New-AzureRMMediaService -Tags @{TagName="TagValue"}
    

    應變更為

    New-AzMediaService -Tag @{TagName="TagValue"}
    

Az.Monitor (先前是 AzureRM.Insights)

  • 已移除複數名稱和CategoriesTimegrains參數,以使用 從 Set-AzDiagnosticSetting Cmdlet 腳本中移除單一參數名稱

    Set-AzureRmDiagnosticSetting -Timegrains PT1M -Categories Category1, Category2
    

    應變更為

    Set-AzDiagnosticSetting -Timegrain PT1M -Category Category1, Category2
    

Az.Network (先前是 AzureRM.Network)

  • 已從 Get-AzServiceEndpointPolicyDefinition Cmdlet 移除已被ResourceId取代的參數
  • 已從 PSVirtualNetwork 物件中移除已被EnableVmProtection取代的屬性
  • 已移除已被取代的 Set-AzVirtualNetworkGatewayVpnClientConfig Cmdlet

腳本不應再根據這些欄位的值做出處理決策。

Az.OperationalInsights (先前是 AzureRM.OperationalInsights)

  • 已移除的預設參數集 Get-AzOperationalInsightsDataSource ,並 ByWorkspaceNameByKind 成為預設參數集

    使用列出數據源的腳本

    Get-AzureRmOperationalInsightsDataSource
    

    應該變更以指定Kind

    Get-AzOperationalInsightsDataSource -Kind AzureActivityLog
    

Az.RecoveryServices (先前是 AzureRM.RecoveryServices、AzureRM.RecoveryServices.Backup 和 AzureRM.RecoveryServices.SiteRecovery)

  • 已從 New/Set-AzRecoveryServicesAsrPolicy Cmdlet 移除Encryption參數
  • TargetStorageAccountName 參數現在是 Cmdlet 中 Restore-AzRecoveryServicesBackupItem 受控磁碟還原的必要參數
  • 已移除 StorageAccountName Cmdlet 中的 Restore-AzRecoveryServicesBackupItemStorageAccountResourceGroupName 參數
  • 已移除 NameCmdlet 中的 Get-AzRecoveryServicesBackupContainer 參數

Az.Resources (先前是 AzureRM.Resources)

  • 已從 New/Set-AzPolicyAssignment Cmdlet 移除Sku參數

  • 已從 New-AzADServicePrincipalNew-AzADSpCredential Cmdlet 自動產生已移除Password的參數密碼,提供密碼的腳稿:

    New-AzAdSpCredential -ObjectId 1f99cf81-0146-4f4e-beae-2007d0668476 -Password $secPassword
    

    應該變更以從輸出擷取密碼:

    $credential = New-AzAdSpCredential -ObjectId 1f99cf81-0146-4f4e-beae-2007d0668476
    $secPassword = $credential.Secret
    

Az.ServiceFabric (先前是 AzureRM.ServiceFabric)

  • 下列 Cmdlet 傳回類型已變更:
    • 已移除 類型的 ApplicationHealthPolicy 屬性ServiceTypeHealthPolicies
    • 已移除 類型的 ClusterUpgradeDeltaHealthPolicy 屬性ApplicationHealthPolicies
    • 已移除 類型的 ClusterUpgradePolicy 屬性OverrideUserUpgradePolicy
    • 這些變更會影響下列 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)

  • 已從 Set-AzSqlDatabaseBackupLongTermRetentionPolicy Cmdlet 移除StateResourceId參數
  • 已移除已被取代的 Cmdlet:Get/Set-AzSqlServerBackupLongTermRetentionVault、、Get/Start/Stop-AzSqlServerUpgrade、、Get/Set-AzSqlDatabaseAuditingPolicyGet/Set-AzSqlServerAuditingPolicyRemove-AzSqlDatabaseAuditingRemove-AzSqlServerAuditing
  • 已從 Get-AzSqlDatabaseBackupLongTermRetentionPolicy Cmdlet 移除已被取代的參數Current
  • 已從 Get-AzSqlServerServiceObjective Cmdlet 移除已被取代的參數DatabaseName
  • 已從 Set-AzSqlDatabaseDataMaskingPolicy Cmdlet 移除已被取代的參數PrivilegedLogin

Az.儲存體 (先前是 Azure.儲存體 和 AzureRM.儲存體)

  • 若要支援僅使用記憶體帳戶名稱建立 Oauth 記憶體內容,預設參數集已變更為 OAuthParameterSet
    • 範例: $ctx = New-AzureStorageContext -StorageAccountName $accountName
  • Cmdlet Location 中的 Get-AzStorageUsage 參數已變成必要參數
  • 儲存體 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()

Set Blob Tier

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)

  • 已從PSAppServicePlanPSCertificatePSCloningInfo、 和 PSSite 物件中移除已被取代的屬性