0
0
Azurecloud~5 mins

Azure AD tenants and directories - Commands & Configuration

Choose your learning style9 modes available
Introduction
Azure Active Directory (Azure AD) tenants are like separate accounts that hold users, groups, and apps. Each tenant is a directory that keeps these identities safe and organized. This helps companies manage who can access their cloud resources.
When you want to keep user accounts and permissions separate for different companies or projects.
When you need to control access to cloud apps and services for your organization.
When you want to create a secure space for your employees to sign in and use Microsoft services.
When you want to manage multiple organizations or subsidiaries under one cloud platform.
When you need to set up single sign-on for your apps using a trusted identity provider.
Commands
This command logs you into your Azure account so you can manage your Azure AD tenants and directories.
Terminal
az login
Expected OutputExpected
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code ABCD1234 to authenticate. You have logged in. Now let us find all the subscriptions to which you have access...
This command lists all Azure AD tenants (directories) associated with your Azure account.
Terminal
az account tenant list
Expected OutputExpected
[ { "tenantId": "11111111-2222-3333-4444-555555555555", "displayName": "Contoso Tenant" }, { "tenantId": "66666666-7777-8888-9999-000000000000", "displayName": "Fabrikam Tenant" } ]
This command switches your current session to use the specified Azure AD tenant by its tenant ID.
Terminal
az account set --tenant 11111111-2222-3333-4444-555555555555
Expected OutputExpected
No output (command runs silently)
--tenant - Specifies the tenant ID to switch to
This command lists all users in the currently selected Azure AD tenant in a readable table format.
Terminal
az ad user list --output table
Expected OutputExpected
DisplayName UserPrincipalName ObjectId ------------------- --------------------------------- ------------------------------------ Alice Johnson alice.johnson@contoso.com 12345678-90ab-cdef-1234-567890abcdef Bob Smith bob.smith@contoso.com 23456789-0abc-def1-2345-67890abcdef1
--output - Formats the output for easier reading
Key Concept

If you remember nothing else, remember that an Azure AD tenant is a secure container for identities and switching tenants changes the context of your Azure commands.

Common Mistakes
Trying to manage users without switching to the correct tenant first.
Commands will run against the wrong directory, causing confusion or errors.
Always use 'az account set --tenant <tenant-id>' to select the right tenant before managing its resources.
Assuming one Azure account has only one tenant.
Many users have access to multiple tenants, so commands might not affect the intended directory.
List all tenants with 'az account tenant list' and pick the correct one.
Summary
Use 'az login' to sign in to your Azure account.
List all Azure AD tenants with 'az account tenant list'.
Switch to the desired tenant using 'az account set --tenant <tenant-id>'.
Manage users and resources within the selected tenant.