共用方式為


Azure PowerShell 的常見問題集

什麼是 Azure PowerShell?

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

如何在 Azure PowerShell 中停用重大變更警告訊息?

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

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

在匯入 AzAz.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 安全。