I'm trying to use az
against my Azure account. My account has two directories: one for personal (default) and one for business. I need to "switch to" the business directory so that az
has access to the correct resources. However, I cannot find any way to achieve this via the command line, so when I do az group list
I see the resource groups from my personal directory, not the business one.
How can I switch Azure directory from the CLI?
1st way: Click Switch tenant option. 2nd way: Click on the user id on the top right side, and choose Switch directory. In the switch tenant Select the Azure AD tenant and click switch, when you select it from Directory + subscription wizard double click the directory to choose it.
How to sign into the Azure CLI. Before using any Azure CLI commands with a local install, you need to sign in with az login. Run the login command. If the CLI can open your default browser, it will initiate authorization code flow and open the default browser to load an Azure sign-in page.
The Startup directory shows the default directory when you sign in to the Azure portal. To choose a different startup directory, select change to go to the Appearance + startup views page, where you can change this option. To see a full list of directories to which you have access, select All Directories.
Subscription and directory is not the same. You can have access to several subscriptions in your work directory for example.
To login to a different (non-default) directory, use the --tenant
option with the az login
command, passing the FQDN for the directory, e.g.
az login --tenant yourdir.onmicrosoft.com
You can find the FQDN in Azure Portal when listing the directories.
When logged into a directory, you can see list of all your available subscriptions.
# List of the tenants:
az account tenant list
[
{
"id": "/tenants/91358f27-xxxx-xxxxxxxxxxx",
"tenantId": "91358f27-xxxx-xxxxxxxxxxx"
},
{
"id": "/tenants/cf39b7bf-xxxx-xxxxxxxxxxx",
"tenantId": "cf39b7bf-xxxx-xxxxxxxxxxx"
}
]
# Select the tenant ID:
az login --tenant cf39b7bf-xxxx-xxxxxxxxxxx --allow-no-subscriptions
# Set a validated subscription:
az account set --subscription "Pago por uso"
# Verify
az account list -o table
Ugh, nevermind. For some reason the CLI calls them subscriptions when the portal calls them directories. So I needed az account set --subscription $SUBSCRIPTION_ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With