你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

有关 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。