This is a short blog post with a PowerShell cmdlet that will return you the Azure AD tenant id for a given domain.
function Get-AzureADTenantId
{
[CmdletBinding()]
[Alias()]
[OutputType([string])]
Param
(
# Param1 help description
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$DomainName
)
Begin
{
Load-Assembly System.Xml.Linq | Out-Null
}
Process
{
$FederationMetadata = Get-AzureADFederationMetadata -Domain $DomainName
$FederationMetadata.EntityDescriptor.entityID -split "/" | where{$_ -match "^[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{12}$"}
}
End
{
}
}
Get-AzureADTenantId microsoft.com
Get-AzureADTenantId microsoft.onmicrosoft.com