7

If you want to connect to a specific subscription with Az.Accounts, you do something like:

Connect-AzAccount -SubscriptionId <guid> etc...

I see that there is no possibility of specifying the SubscriptionId with az login.

If my account for example manages multiple subscriptions, what would happen when listing all resource groups?

How can I login on only one subscription?

Vivere
  • 1,919
  • 4
  • 16
  • 35

1 Answers1

18

Use az account set to set the subscription after az login, as in:

az account set --subscription <subscription name or id>
WaitingForGuacamole
  • 3,744
  • 1
  • 8
  • 22
  • 1
    not sure why that merits a downvote, as it works, and directly answers the user's question. Unless the purpose is to discourage people from answering questions that have already been answered elsewhere? – WaitingForGuacamole Mar 17 '21 at 14:14
  • 1
    This solves the problem till the next login. Any chance we can permanently change the default subscription? – Eliise S Jan 13 '23 at 20:42
  • 1
    Not that I can find. Nothing that survives an `az account clear`/`az login` pair. In addition, while many Azure CLI commands respect the current subscription setting (which appears to be the first subscription in an undetermined order), Microsoft are saying that they're moving us toward specifying it on all commands (https://learn.microsoft.com/en-us/cli/azure/manage-azure-subscriptions-azure-cli#get-the-active-subscription) – WaitingForGuacamole Mar 23 '23 at 19:04