Member-only story

Azure LogIn for multiple tenants

Ripon Banik
3 min readNov 8, 2023

--

Switch your tenant without logging in again

Overview

Azure organization works via Tenants and Subscriptions. One tenant can have multiple subscriptions.

When you log into Azure via cli for programmatic access, it sets a default profile with context of tenant.

That means, you need to log multi times when you want to switch the tenants. This article I will run through methods, that you can use to switch it automatically.

How To using PowerShell

When you are using PowerShell, you can use the steps below.

Connect to your Azure Account using Device Authentication. It will ask you to use web browser to open the page https://microsoft.com/devicelogin and enter a code xxxx to authenticate.

Connect-AzAccount -UseDeviceAuthentication

Since it sets your profile with current context, you can save it to a file. Do this for all of your other login but use different filename.

Save-AzProfile -Path ./MyAzureDemoProfile.json

Under the hood, it puts all the contexts into a file that you have specified and set your current context as default into that file.

--

--

Ripon Banik
Ripon Banik

Written by Ripon Banik

A Cloud and DevSecOps Engineer and Consultant, passionate about simplification of technology and make it consumable. https://www.linkedin.com/in/riponbanik/

No responses yet