Manage multiple Azure subscriptions

If you are brand new to Azure, you probably only have a single subscription. But if you have been using Azure for a while, you may have created multiple Azure subscriptions. If so, you can configure Azure CLI 2.0 to execute commands against a particular subscription.

The Azure Cloud Shell (in public preview) is a web-based shell that is preconfigured to simplify using Azure tools. With Cloud Shell, you always have the most up-to-date version of the tools available and you don’t have to install, update or separately log in. Click the Try It button at the top right of a code block to launch the Cloud Shell. Then, use the Copy button to copy and paste the sample code into the Cloud Shell.

You can also open the Cloud Shell from the Azure portal by clicking the Cloud Shell button on the top navigation.

  1. Get a list of all subscriptions in your account.

    az account list --output table
    
    Name                                         CloudName    SubscriptionId                        State     IsDefault
    -------------------------------------------  -----------  ------------------------------------  --------  -----------
    My Production Subscription                   AzureCloud   XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX  Enabled
    My DevTest Subscription                      AzureCloud   XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX  Enabled   True
    My Demos                                     AzureCloud   XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX  Enabled
    
  2. Set the default.

    az account set --subscription "My Demos"
    

    Note

    The --subscription parameter takes either the subscription name or the subscription ID.

You can verify the change by running the az account list --output table command again.

Once you set your default subscription, all subsequent Azure CLI commands run against this subscription.