Az 1.0.0 的重大變更

本檔提供 AzureRM 6.x 與新 Az 模組 1.x 版和更新版本之間變更的詳細資訊。 目錄將協助引導您完成完整的移轉路徑,包括可能影響指令碼的模組特定變更。

如需開始從 AzureRM 移轉至 Az 的一般建議,請參閱 開始從 AzureRM 移轉至 Az。

Important

Az 1.0.0 和 Az 2.0.0 之間也有重大變更。 遵循本指南從 AzureRM 更新至 Az 之後,請參閱 Az 2.0.0 重大變更 ,以瞭解您是否需要進行其他變更。

目錄

一般重大變更

本節詳細說明 Az 模組重新設計過程中的一般重大變更。

Cmdlet 名詞前置詞變更

在 AzureRM 模組中,cmdlets 使用 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 參考。

Important

停用別名時,請確定已針對 已 啟用別名的所有範圍停用別名。

模組名稱變更

模組名稱已從 AzureRM.* 變更為 Az.*,但下列模組除外:

AzureRM 模組 Az 模組
Azure Storage Az.Storage
Azure.分析服務 Az.AnalysisServices
AzureRM.Profile Az.帳戶
AzureRM.Insights Az.Monitor
AzureRM.DataFactories Az.DataFactory
AzureRM.DataFactoryV2 Az.DataFactory
AzureRM.RecoveryServices.Backup Az.復原服務
AzureRM.RecoveryServices.SiteRecovery Az.復原服務
AzureRM.Tags(AzureRM 標籤) Az.Resources
AzureRM.MachineLearningCompute Az.MachineLearning
AzureRM.UsageAggregates Az.Billing
AzureRM.Consumption (Azure 資源管理消耗) 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

必須變更,才能使用新的模組和 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 框架。

暫時移除使用 PSCredential 的使用者登入

由於 .NET 標準認證流程的變更,我們暫時移除透過 PSCredential 的使用者登入功能。 此功能將於 2019 年 1 月 15 日 PowerShell 5.1 for Windows 版本中重新引入。 這點在此 GitHub 問題中有詳細討論。

預設使用裝置代碼登入,而非透過網頁瀏覽器提示

由於 .NET 標準認證流程的變更,我們在互動式登入時將裝置登入作為預設登入流程。 透過網頁瀏覽器的登入方式將作為預設功能於 2019 年 1 月 15 日的 PowerShell 5.1 for Windows 版本中重新引入。 屆時,用戶將能夠使用 Switch 參數來選擇裝置登入。

模組重大變更

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

Az.ApiManagement (先前為 AzureRM.ApiManagement)

  • 已移除下列 cmdlet:
    • New-AzureRmApiManagementHostnameConfiguration
    • Set-AzureRmApiManagementHostnames
    • Update-AzureRmApiManagementDeployment 更新 Azure API 管理部署
    • 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 已在 Cmdlet 中 New-AzDataFactoryEncryptValue 變成必要參數
  • 已移除 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, EncryptionConfigFirewallStateFirewallRulesVirtualNetworkRulesTrustedIdProviderStateTrustedIdProvidersDefaultGroupNewTierCurrentTierFirewallAllowAzureIpsPSDataLakeStoreAccountBasic 使用PSDatalakeStoreAccount傳回Get-AzDataLakeStoreAccount的任何腳本都不應參考這些屬性。

Az.KeyVault (先前為 AzureRM.KeyVault)

  • PurgeDisabled屬性已從PSKeyVaultKeyAttributes、PSKeyVaultKeyIdentityItem和PSKeyVaultSecretAttributes物件中移除,腳本不應再參考屬性PurgeDisabled來做出處理決策。

Az.Media (先前為 AzureRM.Media)

  • 從 Cmdlet 腳本中移除已棄用的Tags屬性別名New-AzMediaService

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

    應變更為

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

Az.Monitor (先前為 AzureRM.Insights)

  • 已移除複數名稱 Categories 和 Timegrains 參數,轉為使用 Set-AzDiagnosticSetting cmdlet 指令碼中的單一參數名稱。

    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 受控磁碟還原的必要參數
  • 已移除 StorageAccountNameStorageAccountResourceGroupName Cmdlet 中的 Restore-AzRecoveryServicesBackupItem 參數
  • 已移除 Namecmdlet 中的 Get-AzRecoveryServicesBackupContainer 參數

Az.Resources (先前為 AzureRM.Resources)

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

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

    New-AzAdSpCredential -ObjectId aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb -Password $secPassword
    

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

    $credential = New-AzAdSpCredential -ObjectId aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb
    $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 (更新 AzServiceFabric 耐久性)
      • 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 已在 Cmdlet 中 Get-AzStorageUsage 變成必要參數
  • 儲存 API 方法現在使用以工作為基礎的非同步模式 (TAP),而不是同步 API 呼叫。 下列範例示範新的非同步命令:

Blob 快照

AzureRM:

$b = Get-AzureStorageBlob -Container $containerName -Blob $blobName -Context $ctx
$b.ICloudBlob.Snapshot()

阿茲:

$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()

阿茲:

$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()

阿茲:

$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")

阿茲:

$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物件中移除已棄用的屬性