什么是 Azure PowerShell?
Azure PowerShell 是一组 cmdlet,你可通过它直接使用 PowerShell 管理 Azure 资源。 Az PowerShell 模块已于 2018 年 12 月正式发布。 它现在是与 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 Pow erShell 使用 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。