共用方式為


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

Fully-Qualified 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/01/15 發行版本中,將會為 Windows 的 PowerShell 5.1 重新引入以網頁瀏覽器為基礎的登入作為預設。 屆時,用戶將能夠使用 Switch 參數來選擇裝置登入。

模組重大變更

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

Az.ApiManagement (先前是 AzureRM.ApiManagement)

  • 已移除下列命令指令:
    • New-AzureRmApiManagementHostnameConfiguration
    • Set-AzureRmApiManagementHostnames
    • Update-AzureRmApiManagementDeployment
    • Import-AzureRmApiManagementHostnameCertificate
    • 請改用 Set-AzApiManagement Cmdlet 來設定這些屬性
  • 已移除下列屬性:
    • 已從 PsApiManagementContext移除類型 PsApiManagementHostnameConfiguration 的屬性 PortalHostnameConfigurationProxyHostnameConfigurationManagementHostnameConfigurationScmHostnameConfiguration。 請改用類型 PsApiManagementCustomHostNameConfigurationPortalCustomHostnameConfigurationProxyCustomHostnameConfigurationManagementCustomHostnameConfigurationScmCustomHostnameConfiguration
    • 已從 PsApiManagementContext 移除屬性 StaticIPs。 屬性已分割成 PublicIPAddresses 以及 PrivateIPAddresses
    • 已從 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 會從 PSVirtualMachine 中的 Identity 屬性中移除,而且 PSVirtualMachineScaleSet 物件腳本不應再使用此欄位的值來進行處理決策。
  • PSVirtualMachineScaleSetVM 物件的 InstanceView 屬性類型會從 VirtualMachineInstanceView 變更為 VirtualMachineScaleSetVMInstanceView
  • AutoOSUpgradePolicyAutomaticOSUpgrade 屬性會從 UpgradePolicy 屬性中移除
  • PSSnapshotUpdate 物件中的 Sku 屬性類型從 DiskSku 變更為 SnapshotSku
  • VmScaleSetVMParameterSet 已從 Add-AzVMDataDisk Cmdlet 中移除,您無法再個別將數據磁碟新增至 ScaleSet VM。

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

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

Az.DataLakeAnalytics (先前是 AzureRM.DataLakeAnalytics)

  • 已移除不再支援的 Cmdlet:New-AzDataLakeAnalyticsCatalogSecretRemove-AzDataLakeAnalyticsCatalogSecretSet-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"}
    
  • 已從 PSDataLakeStoreAccountBasic 物件中移除 IdentityEncryptionStateEncryptionProvisioningStateEncryptionConfigFirewallStateFirewallRulesVirtualNetworkRulesTrustedIdProviderStateTrustedIdProvidersDefaultGroupNewTierCurrentTierFirewallAllowAzureIps 屬性。 任何使用從 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 參數
  • Restore-AzRecoveryServicesBackupItem cmdlet 現在在受管理磁碟還原中必須使用 TargetStorageAccountName 參數。
  • 已移除 Restore-AzRecoveryServicesBackupItem Cmdlet 中的 StorageAccountNameStorageAccountResourceGroupName 參數
  • 已移除 Get-AzRecoveryServicesBackupContainer Cmdlet 中的 Name參數

Az.Resources (先前是 AzureRM.Resources)

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

  • Password 參數從 New-AzADServicePrincipalNew-AzADSpCredential Cmdlet 中移除,密碼會自動生成,同時提供密碼的腳本:

    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 傳回類型已變更:
    • 類型 ApplicationHealthPolicy 的屬性 ServiceTypeHealthPolicies 已被移除。
    • 已移除類型 ClusterUpgradeDeltaHealthPolicy 的屬性 ApplicationHealthPolicies
    • 已移除類型 ClusterUpgradePolicy 的屬性 OverrideUserUpgradePolicy
    • 這些變更會影響下列命令指令:
      • 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-AzSqlServerBackupLongTermRetentionVaultGet/Start/Stop-AzSqlServerUpgradeGet/Set-AzSqlDatabaseAuditingPolicyGet/Set-AzSqlServerAuditingPolicyRemove-AzSqlDatabaseAuditingRemove-AzSqlServerAuditing
  • 已從 Get-AzSqlDatabaseBackupLongTermRetentionPolicy Cmdlet 移除已淘汰的參數 Current
  • 已從 Get-AzSqlServerServiceObjective Cmdlet 移除已淘汰的參數 DatabaseName
  • 已從 Set-AzSqlDatabaseDataMaskingPolicy Cmdlet 移除已淘汰的參數 PrivilegedLogin

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)

  • 已從 PSAppServicePlanPSCertificatePSCloningInfoPSSite 物件中移除已淘汰的屬性