Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to switch to other Azure AD tenant using PowerShell and Azure CLI

This is small guide shows how you can switch or change Azure Active Directory tenant using Powershell and Azure CLI. Before The first step I will show from portal how to switch or change to another domain in Azure active directory. Once you login into portal.azure.com either go into menu and select Azure Active Direcory from list or search for the same in search bar and click on it.

There are 2 ways from the portal to switch to another tenant, As per the screenshot my Starting position is on the Azure Active Directory Overview page.

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.

You can view the connected Tenant information under Azure Active directory on the Overview page.

PowerShell az module

The above steps are for GUI version. I was automating few stuff and I wanted to switch to another domain. For the task I chose Powershell az module. Below Powershell cmdlets help to switch to another Azure AD.

Powershell Azure Az module Install-Package cannot convert value 2.0.0-preview to type system.version 

#Below two commands import module az and connects to Azure subscription.
Import-Module az
Connect-AzAccount

#Fetch the list of available Tenant Ids.
Get-AzTenant

#Grab the tenant Id Switch to another active directory tenant.
Set-AzContext -TenantId XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

#Test and list the users in the directory to verify.
Get-AzADUser

Azure CLI

Next steps are for Azure CLI, Login and get the list of added domain tenants with below commands.

#Azure CLI Login
az login

#List of the tenants
az account tenant list

Although you can skip above two commands and directly login into required tenant, You can find Primary domain tenant name on the portal.azure.com on the Azure active directory. Just to note, I don't have subscription so I am using the parameter --allow-no-subscriptions.

az login --tenant vcloud-lab.com.onmicrosoft.com --allow-no-subscriptions

Once login is successful on to required subscription, I can test the users list in the given Azure AD tenant.

#list of users list in selected tenant
az ad user list

Useful Articles
CREATE NEW NSG (NETWORK SECURITY GROUP - VIRTUAL FIREWALL ACL) ON MICROSOFT AZURE  
POWERSHELL - EXPORT AZURE NSG (NETWORK SECURITY GROUP) RULES TO EXCEL
MICROSOFT AZURE POWERSHELL: CREATING NEW NSG (NETWORK SECURITY GROUP)
MICROSOFT AZURE POWERSHELL: CLONING (COPING) OR IMPORTING EXISTING NSG (NETWORK SECURITY GROUP) FROM EXCEL
Part 1: Create and deploy a website with Microsoft Azure web app service plan
Part 2: Configure a custom domain in Azure Web Apps
Part 3: Uploading to Azure Web Apps Using FTP
Part 4: Add and manage TLS SSL certificates on Azure Web App



This post first appeared on Tales From Real IT System Administrators World And Non-production Environment, please read the originial post: here

Share the post

How to switch to other Azure AD tenant using PowerShell and Azure CLI

×

Subscribe to Tales From Real It System Administrators World And Non-production Environment

Get updates delivered right to your inbox!

Thank you for your subscription

×