Time changes everything. I was looking to do the same recently and came up with this:

added 02/17/2021

Stable Portal Page thanks Palec

added 12/18/2017

As indicated by shadowbq, the DirectoryId and TenantId both equate to the GUID representing the ActiveDirectory Tenant. Depending on context, either term may be used by Microsoft documentation and products, which can be confusing.

  • You have access to the Azure Portal

The tenant ID is tied to ActiveDirectoy in Azure

  • Navigate to Dashboard
  • Navigate to ActiveDirectory
  • Navigate to Manage / Properties
  • Copy the “Directory ID”

Azure ActiveDirectory Tenant ID:


My team really got sick of trying to find the tenant ID for our O365 and Azure projects. The devs, the support team, the sales team, everyone needs it at some point and never remembers how to do it.

So we’ve built this small site in the same vein as whatismyip.com. Hope you find it useful!

How to find my Microsoft 365, Azure or SharePoint Online tenant ID?


In the Azure CLI (I use GNU/Linux):

$ azure login  # add "-e AzureChinaCloud" if you're using Azure China

This will ask you to login via https://aka.ms/devicelogin or https://aka.ms/deviceloginchina

$ azure account show
info:    Executing command account show
data:    Name                        : BizSpark Plus
data:    ID                          : aZZZZZZZ-YYYY-HHHH-GGGG-abcdef569123
data:    State                       : Enabled
data:    Tenant ID                   : 0XXXXXXX-YYYY-HHHH-GGGG-123456789123
data:    Is Default                  : true
data:    Environment                 : AzureCloud
data:    Has Certificate             : No
data:    Has Access Token            : Yes
data:    User name                   : nico@XXXXXXX.onmicrosoft.com
info:    account show command OK

or simply:

azure account show --json | jq -r '.[0].tenantId'

or the new az:

az account show --subscription a... | jq -r '.tenantId'
az account list | jq -r '.[].tenantId'

I hope it helps


The tenant id is also present in the management console URL when you browse to the given Active Directory instance, eg,


Azure Mgmt Console Active Directory


Just to add a new method to an old (but still relevant question). In the new portal, clicking the help icon from any screen and selecting ‘Show Diagnostics‘ will show you a JSON document containing all your tenant information including TenantId, Tenant Name, and much, much more useful information

enter image description here


Via PowerShell anonymously:

(Invoke-WebRequest https://login.windows.net/YOURDIRECTORYNAME.onmicrosoft.com/.well-known/openid-configuration|ConvertFrom-Json).token_endpoint.Split("https://stackoverflow.com/")[3]


Another way to get it from App registrations

Azure Active Directory -> App registrations -> click the app and it will show the tenant ID like this

enter image description here


You can run a simple curl call to get the tenant id of an azure subscription without any authentication.

make a curl call to :


The request fails but you will be able to get the tenant id from the response header. The tenant id is present in line followed by “WWW-Authenticate: Bearer authorization_uri=”https://login.windows.net/”

you can use curl -v to show the response header.


As of now (06/07/2018), an easy approach would be running az account show in the Azure Cloud Shell (requires a Storage Account) in the Azure Portal.

— Command —

az account show

— Command Output —

  "environmentName": "AzureCloud",
  "id": "{Subscription Id (GUID)}",
  "isDefault": true,
  "name": "{Subscription Name}",
  "state": "Enabled",
  "tenantId": "{Tenant Id (GUID)}",
  "user": {
    "cloudShellID": true,
    "name": "{User email}",
    "type": "user"

Find more details on Azure Cloud Shell at Overview of Azure Cloud Shell | Microsoft Docs.


If you have installed Azure CLI 2.0 in your machine, you should be able to get the list of subscription that you belong to with the following command,

az login

if you want to see as a table output you could just use

az account get-access-token --query tenant --output tsv

or you could use the Rest API

Tenants – List | Microsoft Docs

Use the Azure CLI

az account get-access-token --query tenant --output tsv


In PowerShell:

Add-AzureRmAccount #if not already logged in 
Get-AzureRmSubscription -SubscriptionName <SubscriptionName> | Select-Object -Property TenantId


If you have Azure CLI setup, you can run the command below,

az account list

or find it at ~/.azure/credentials

Step 1: Login to Microsoft Azure portal

Step 2: Search Azure Active Directory

Step 3: Click on overview and find the tenant id from tenant information section

enter image description here

enter image description here

From Java:

public static String GetSubscriptionTenantId (String subscriptionId) throws ClientProtocolException, IOException
    String tenantId = null;
    String url = "https://management.azure.com/subscriptions/" + subscriptionId + "?api-version=2016-01-01";

    HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet(url);
    HttpResponse response = client.execute(request);

    Header[] headers = response.getAllHeaders();
    for (Header header : headers)
        if (header.getName().equals("WWW-Authenticate"))
            // split by '"' to get the URL, split the URL by "https://stackoverflow.com/" to get the ID
            tenantId = header.getValue().split(""")[1].split("https://stackoverflow.com/")[3];

    return tenantId;

A simple way to get the tenantID is:

Connect-MsolService -cred $LiveCred  #sign in to tenant

(Get-MSOLCompanyInformation).objectid.guid  #get tenantID

Using Azure Portal:

  • Step1: Login to azure portal and search for Azure Active Directory and select it.
  • Step2: In the overview page of Azure Active Directory, find the tenant ID.

enter image description here

Using Azure CLI:

Use one of the commands az login, az account list, or az account tenant list. Find the TenantId property for each of subscriptions in the output from each command.

Using Powershell

Use the below command in powershell cmdlet.



Azure CLI


You can also get the tenant id, in fact all subscription details by logging into the url resources.azure.com

For AAD-B2C it is fairly simple. From Azure Portal with a B2C directory associated, go to your B2C directory (I added the “Azure AD B2C” to my portal’s left menu). In the B2C directory click on “User flows (policies) directory menu item. In the policies pane click on one of your policies you previously added to select it. It should open a pane for the policy. Click “Properties”. In the next pane is a section, “Token compatibility settings” which has a property “Issuer”. Your AAD-B2C tenant GUID is contained in the URL.

The one working for me is this (after az login):

 az account show |grep tenantId | awk {'print $2'} |tr -d '[:punct:]'

I use following to get tenant id

az account show --query homeTenantId --output tsv

Go to the Azure portal > Azure Active Direcrory. On the main screen, you should see your tenant ID.

xxx@Azure:~$ az ad sp create-for-rbac
Retrying role assignment creation: 1/36
  "appId": "401143c2-95ef-4792-9900-23e07f7801e7",
  "displayName": "azure-cli-2018-07-10-20-31-57",
  "name": "http://azure-cli-2018-07-10-20-31-57",
  "password": "a0471d14-9300-4177-ab08-5c45adb3476b",
  "tenant": "e569f29e-b008-4cea-b6f0-48fa8532d64a"