編輯

共用方式為


關於 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

必須先設定此環境變數,才能匯入 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 不安全。