Change Azure directory from command line
Solution 1
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.
Solution 2
# 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
Solution 3
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
Related videos on Youtube
me--
Updated on June 04, 2022Comments
-
me-- almost 2 years
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 thataz
has access to the correct resources. However, I cannot find any way to achieve this via the command line, so when I doaz group list
I see the resource groups from my personal directory, not the business one.How can I switch Azure directory from the CLI?
-
Marki555 over 4 yearsThis way you only change the active subscription in your default directory. You need to specify the directory during
az login
as shown in my answer. -
user232548 over 3 yearsAlso note you may need to add param
--allow-no-subscriptions
in case there is no subscription for the directory. So use like this:az login --tenant yourdir.onmicrosoft.com --allow-no-subscriptions
. E.g. we have directory for Azure AD B2C created and seems to require this, but not sure why.