How to a Find Microsoft 365 Tenant ID Without Tenant Access

  • Post author:
  • Post category:Microsoft Entra
  • Post last modified:
  • Reading time:3 mins read
  • Post published:

The unique identifier of any Microsoft 365 tenant is public information. This means there are no direct security concerns about someone else knowing your tenant’s ID other than that it could be used for social engineering or to interrogate further holes in your security that could then be exploited.

Nevertheless, there are also some legitimate reasons to want to know a tenant’s ID, such as if you need to authenticate to it using any authentication mechanism, if you need to establish a tenant-to-tenant relationship, or even if you are updating documentation. 

Let’s look at the methods you can use to find the ID of any Microsoft 365 tenant.

Using PowerShell

The first and my favourite option is to use PowerShell. Below, I have written a small function that queries a public API and returns the ID of any Microsoft 365 tenant.

Function Find-TenantID {

<#
  .AUTHOR
    Daniel Bradley
    ourcloudnetwork.co.uk

  .DESCRIPTION
    A small PowerShell function to quickly find the tenant ID of any Micorosft tenant using public APIs without authorisation.

  .EXAMPLE
    Find-TenantID -domain ourcloudnetwork.com
#>

     param(
        [Parameter(Position=0,mandatory=$true)]
        [string] $domain
    )

    try {
        $response = Invoke-RestMethod -UseBasicParsing -Uri "https://odc.officeapps.live.com/odc/v2.1/federationprovider?domain=$domain"
    }
    Catch {
        Return "Unable to run request"
    }

    #Return
    $response.tenantid
}

Use the example below and replace the primary tenant domain with your own to get the result.

Find-TenantID -domain ourcloudnetwork.com

If you have entered a valid domain, your output should look like the following:

Find-TenantID
Find-TenantID

Alternatively, If you want to incorporate this code into your script without the use of a function, you can take the following two lines to get the tenant ID:

$domain = "ourcloudnetwork.com"
Invoke-RestMethod -UseBasicParsing -Uri "https://odc.officeapps.live.com/odc/v2.1/federationprovider?domain=$domain" | Select -expand tenantid

Using an online tool

Alternatively, and for ease of use, I have developed a small web app running on Azure App Services using Next.js, which performs the same API call as the above PowerShell script.  The tool can be accessed here: entraid.ourcloudnetwork.com

Enter the primary domain name for the target tenant and click Get tenant ID. The tenant ID will be instantly returned to the text box.

Get Microsoft 365 tenant id
Get Microsoft 365 tenant id

Using Conditional Access

The final option is to use the Conditional Access policy creation wizard from inside another (any) tenant to enumerate the tenant ID of any tenant using the primary domain name. Follow the below steps to enumerate a tenant ID using Conditional Access:

1. Log in to entra.microsoft.com

2. Expand Protection and select Conditional Access.

3. Select Policies > New policy.

4. Click Users, then under Include, select Users or External Users. Then under Specify external Microsoft Entra organizations, click Select and type in the tenant domain name.

Obtain tenant id from Conditional Access
Obtain tenant id from Conditional Access

You can then copy and paste the tenant ID as it is displayed in the results area.

Daniel Bradley

Daniel Bradley is a UK-based technical architect and Microsoft MVP in Security. He specialises in Microsoft Entra, Intune, and Microsoft Graph PowerShell and is the author of Microsoft Graph PowerShell for Administrators. He writes and edits Our Cloud Network using experience gained from working with Microsoft cloud environments.

Leave a Reply