共用方式為


關於 Azure PowerShell 的常見問題集

什麼是 Azure PowerShell?

Azure PowerShell 是一組 Cmdlet,可讓您直接使用 PowerShell 管理 Azure 資源。 在 2018 年 12 月,Az PowerShell 模組已正式推出。 這個模組現在是用來與 Azure 互動的建議 PowerShell 模組。 若要深入了解 Az PowerShell 模組,請參閱 Az PowerShell 模組簡介

如何停用 Azure PowerShell 中的中斷性變更警告訊息?

若要隱藏 Azure PowerShell 中的中斷性變更警告訊息,您必須將環境變數 SuppressAzurePowerShellBreakingChangeWarnings 設定為 true

Set-Item -Path Env:\SuppressAzurePowerShellBreakingChangeWarnings -Value $true

匯入 Az 或 Az.Accounts PowerShell 模組之前,必須先設定此環境變數,才能在目前的 PowerShell 會話中生效。

如需在 Azure PowerShell 中停用重大變更警告訊息的其他方法,請參閱 設定 Azure PowerShell 全域設定

如何在 Azure PowerShell 中停用 AzureRM 淘汰警告訊息?

若要隱藏 Azure PowerShell 中的 AzureRM 淘汰警告訊息,您必須將環境變數 SuppressAzureRmModulesRetiringWarning 設定為 true

Set-Item -Path Env:\SuppressAzureRmModulesRetiringWarning -Value $true

上述範例的一項缺點是您必須針對每個新的 PowerShell 工作階段執行此命令,除非您將此命令新增至 PowerShell 設定檔中。

若要永久設定環境變數,您也可以使用下列範例。

[System.Environment]::SetEnvironmentVariable('SuppressAzureRmModulesRetiringWarning', 'true', [System.EnvironmentVariableTarget]::User)

如何在 Azure PowerShell 中判斷 HTTP 重試次數上限?

針對一般 HTTP 回應 (回應狀態碼為 429 除外),Azure PowerShell 會使用 AZURE_PS_HTTP_MAX_RETRIES 環境變數中定義的值。 其最小值為 0。 如果未指定,Azure PowerShell 會使用 SDK 預設值。

[System.Environment]::SetEnvironmentVariable('AZURE_PS_HTTP_MAX_RETRIES ', 3, [System.EnvironmentVariableTarget]::User)

如果 HTTP 回應狀態碼為 429,Azure PowerShell 會使用 AZURE_PS_HTTP_MAX_RETRIES_FOR_429 環境變數中定義的值。 其最小值為 1。 狀態碼 429 的重試時間總計為 (AZURE_PS_HTTP_MAX_RETRIES + 1) * AZURE_PS_HTTP_MAX_RETRIES_FOR_429 - 1。 如果未指定,Azure PowerShell 會使用 SDK 預設值。

[System.Environment]::SetEnvironmentVariable('AZURE_PS_HTTP_MAX_RETRIES_FOR_429 ', 3, [System.EnvironmentVariableTarget]::User)

如何在 PowerShell 中將 SecureString 轉換成純文字?

您可以使用下列代碼段,將 SecureString ($secureString) 轉換成純文字 ($plainText):

$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($secureString)
try {
    $plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
    # Perform operations with the contents of $plaintext in this section.
} finally {
    # The following line ensures that sensitive data is not left in memory.
    $plainText = [System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
}

注意: 小心處理純文本,因為它比 SecureString 不安全。