Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Azure directory from command line

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?

like image 536
me-- Avatar asked Mar 25 '19 03:03

me--


People also ask

How do I change Azure directory in PowerShell?

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 do I access Azure command-line?

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.

How do I change the default directory in Azure portal?

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.


Video Answer


3 Answers

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 Directories in Azure Portal

like image 164
Marki555 Avatar answered Oct 18 '22 05:10

Marki555


# 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
like image 29
Jhonny Ramirez Zeballos Avatar answered Oct 18 '22 05:10

Jhonny Ramirez Zeballos


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

like image 29
me-- Avatar answered Oct 18 '22 06:10

me--