Frequently asked questions about Azure PowerShell

What is Azure PowerShell?

Azure PowerShell is a set of cmdlets that allows you to manage Azure resources directly with PowerShell. In December 2018, the Az PowerShell module became generally available. It's now the recommended PowerShell module for interacting with Azure. To learn more about the Az PowerShell module, see Introducing the Az PowerShell module.

How do I disable breaking change warning messages in Azure PowerShell?

To suppress the breaking change warning messages in Azure PowerShell, you'll need to set the environment variable SuppressAzurePowerShellBreakingChangeWarnings to true.

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

This environment variable must be set before importing the Az or Az.Accounts PowerShell module for it to take effect in the current PowerShell session.

For additional methods to disable breaking change warning messages in Azure PowerShell, see Configure Azure PowerShell global settings.

How do I disable the AzureRM retirement warning message in Azure PowerShell?

To suppress the AzureRM retirement warning message in Azure PowerShell, you'll need to set the environment variable SuppressAzureRmModulesRetiringWarning to true.

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

One disadvantage of the previous example is you'll need to run the command for each new PowerShell session unless you add it to your PowerShell profile.

To set the environment variable permanently, you can also use the following example.

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

How do I determine the max HTTP retry times in Azure PowerShell?

For general HTTP response (except response status code is 429), Azure PowerShell uses the value defined in the AZURE_PS_HTTP_MAX_RETRIES environment variable. Its minimum value is 0. If not specified, Azure PowerShell uses the SDK default value.

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

If the HTTP response status code is 429, Azure PowerShell uses the value defined in the AZURE_PS_HTTP_MAX_RETRIES_FOR_429 environment variable. Its minimum value is 1. The total retry times of status code 429 is (AZURE_PS_HTTP_MAX_RETRIES + 1) * AZURE_PS_HTTP_MAX_RETRIES_FOR_429 - 1. If not specified, Azure PowerShell uses the SDK default value.

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

How can I convert a SecureString to plain text in PowerShell?

You can use the following code snippet to convert a SecureString ($secureString) into plain text ($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)
}

Note: Handle plain text carefully, as it is less secure than a SecureString.