Is it possible to login multiple Azure tenancies using different service principals and switch between them in the Azure CLI ?

Pratik Khasnabis 1 Reputation point
2021-08-17T12:38:07.153+00:00

Is it possible to login multiple Azure tenancies using different service principals and switch between them in the Azure CLI ?
AWS CLI has named profiles, something similar.

My scenario is that I have to work with completely different tenancies from the shell. I login using a service principal ID and secret. I want a easy way to switch between the tenancies.

[Note there is no tag for azure-cli]

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
39,709 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JamesTran-MSFT 36,636 Reputation points Microsoft Employee
    2021-08-18T20:27:15.907+00:00

    @Pratik Khasnabis
    Thank you for your time and patience!

    Based off your issue, I tested this scenario out on my end and will post my findings below.

    Findings:
    Using Bash within the Azure Portal - I was able to sign into another Azure AD tenant (using username and password), from a different tenant. However, in order to switch between tenants, I had to re-run az-login.
    124416-image.png

    Azure CLI - I was only able to use it with one user at a time. I logged in with two separate users, using two separate Command prompts, and after logging in with the second user, the first Command prompt, would output the secondary user's info.

    Green box - I signed into Azure CLI initially with my Outlook user, and ran az account tenant list
    Orange box - I signed in with my secondary user within another tenant and re-ran the same commands.
    124345-image.png

    Since this issue is more related to Azure CLI than Azure RBAC, and because Q&A doesn't have an azure-cli tag as you mentioned, you can reach out to our Azure CLI experts via their Stack Overflow forum, to see if there are any easier ways to switch between tenants - Questions tagged azure-cli. Additionally, if you'd like something similar to the AWS CLI named profiles feature to be implemented, I'd recommend creating a feature request with our Azure CLI team via their GitHub link - Issue: Feature request.

    Additional Links:
    Can I access multiple azure accounts with azure-cli from same machine at same time?
    AZURE CLI BASICS: LOGGING IN - 3rd party link

    If you have any other questions, please let me know.
    Thank you for your time and patience throughout this issue.

    ----------

    Please remember to "Accept Answer" if any answer/reply helped, so that others in the community facing similar issues can easily find the solution.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.