Collaborate, Innovate, Automate

Test-M365TenantStatus

This script checks whether one or more domains are on Microsoft 365, and — when checking multiple domains at once — whether they share the same Entra ID tenant or sit on separate tenants entirely. It uses only public DNS records and the unauthenticated OpenID Connect discovery endpoint, so there's no sign-in, no app registration, and no admin permissions needed. Point it at a domain and get an answer in seconds.

Purpose

This kind of quick, no-auth tenant check comes up more often than you'd expect:

How it works

Prerequisites

PowerShell Script

# ── M365 Tenant Detection Script ─────────────────────────────
# Checks whether domains are on Microsoft 365 and whether they
# share a tenant or are on separate tenants.
# No authentication required — uses public DNS and OIDC endpoints.

$domains = @(
    "contoso.com",
    "fabrikam.com"
)

foreach ($domain in $domains) {
    Write-Host "`n── $domain ──────────────────────────" -ForegroundColor Cyan

    # Step 1 — MX record (confirms Exchange Online presence)
    $mx = Resolve-DnsName -Name $domain -Type MX -ErrorAction SilentlyContinue
    $onExchangeOnline = $mx | Where-Object { $_.NameExchange -like "*.mail.protection.outlook.com" }

    if ($onExchangeOnline) {
        Write-Host "  MX: Exchange Online confirmed" -ForegroundColor Green
    } elseif ($mx) {
        Write-Host "  MX: $($mx[0].NameExchange) (not Exchange Online)" -ForegroundColor Yellow
    } else {
        Write-Host "  MX: No record found" -ForegroundColor Red
    }

    # Step 2 — Tenant ID via OpenID Connect discovery endpoint
    try {
        $oidc = Invoke-RestMethod `
            -Uri "https://login.microsoftonline.com/$domain/.well-known/openid-configuration" `
            -ErrorAction Stop
        $tenantId = ($oidc.issuer -split "/")[3]
        Write-Host "  Tenant ID: $tenantId" -ForegroundColor Green
        Write-Host "  Tenant URL: https://login.microsoftonline.com/$tenantId" -ForegroundColor Gray
    }
    catch {
        Write-Host "  Tenant ID: Not resolvable — domain not on M365 or not federated" -ForegroundColor Red
    }
}

Write-Host "`n── Summary ──────────────────────────────────────" -ForegroundColor Cyan
Write-Host "Matching tenant IDs = shared tenant. Different IDs = separate tenants." -ForegroundColor Gray

Usage Notes