Table of Contents
Before you subscribe for a new Microsoft 365 tenant, you will have to choose a name for your tenant. The name will be used in the links for several applications, such as SharePoint Online.
Check Microsoft 365 Tenant Name is Available
There are several ways to achieve this goal.
The first way, we can use the following online services to do a quick check for the availability of a tenant name in Microsoft 365.
Below is an example when the domain duybao3.onmicrosoft.com can use to create a new Microsoft 365 tenant. And the domain duybao2.onmicrosoft.com is already taken.
Using a web browser
The second way, we can check the availability of the new domain you want. For example, if you want the domain name duybao3.onmicrosoft.com.com, let’s enter https://login.microsoftonline.com/duybao3.onmicrosoft.com/FederationMetadata/2007-06/FederationMetadata.xml in a browser.
If you get a message that the tenant couldn’t be found (404), it’s probably available. So, we can use the domain name to create a new Microsoft 365 tenant.
When you browse to an existing Azure AD tenant, you will get the XML data and an HTTP status code 200. Then the domain has already been taken and you’ll need to try a different one.
Verify Azure AD Tenant availability using PowerShell
The third way, I used a very inconspicuous trick to check the tenant availability, and too much of my surprise, it still works, to this day. I used to check for the presence of a particular XML file, one that should be present in all Azure Active Directory tenants, even your own!
The Microsoft identity platform uses the SAML 2.0 protocol to enable applications to supply a single sign-on experience to their users and we can use that to our advantage. Here is what the docs say about the subject.
The tenant-specific endpoint is located at: https://login.microsoftonline.com/<TenantDomainName>/FederationMetadata/2007-06/FederationMetadata.xml.
The <TenantDomainName> placeholder represents a registered domain name or TenantID GUID of an Azure AD tenant. For example, the federation metadata of the contoso.com tenant is at https://login.microsoftonline.com/contoso.com/FederationMetadata/2007-06/FederationMetadata.xml
When you browse to an existing Azure AD tenant, you will get the XML data and an HTTP status code 200.
When you browse to an Azure AD tenant that should not exist, you won’t get the XML data and an HTTP status code 404.
Now, we can go ahead to wrap this up into anything we want, a PowerShell script will be enough for our automation purposes. Here’s a little sample we cooked up, which you can also view on GitHub:
You can copy the below code snippets, change the domain name as you need, and then paste them into a PowerShell window at once or create a PowerShell script to run it locally later.
$domain = 'duybao8.onmicrosoft.com'
$login = 'https://login.microsoftonline.com/'
$fed = '/FederationMetadata/2007-06/FederationMetadata.xml'
$uri = $login + $domain + $fed
if ($PSVersionTable.PSVersion.Major -eq 5) {
$response = try {
(Invoke-WebRequest -Uri $uri -Method GET -ErrorAction Stop).BaseResponse
} catch [System.Net.WebException] {
$_.Exception.Response
}
$StatusCode = $response.StatusCode.Value__
}
if ($PSVersionTable.PSVersion.Major -ge 7) {
$response = Invoke-WebRequest -Uri $uri -Method GET -SkipHttpErrorCheck
$StatusCode = $response.StatusCode
}
switch ($StatusCode) {
200 {
Write-Host "The tenant's name $domain is unavailable." -ForegroundColor Red
}
404 {
Write-Host "The tenant's name $domain is available." -ForegroundColor Green
}
}
For example, we’ve created a PowerShell script named domain.ps1. When running the script, we just need to enter the domain name, the script does the rest.
Additionally, if you don’t want to create a PowerShell script manually. All you need to do is executive the single-line PowerShell script directly:
irm https://bonguides.com/ps/tenantcheck | iex
Using Microsoft Partner Center
The last way, if you have access to Partner Center, you can install the Partner Center PowerShell module to verify Azure AD tenant availability.
Install-Module -Name PartnerCenter -AllowClobber -Scope CurrentUser
Connect-PartnerCenter
Test-PartnerDomainAvailability -Domain 'contoso.onmicrosoft.com'
# Output
Account Environment TenantId
------- ----------- --------
e3d3decc-ee3c-xxxx-8f80-99d59771672e AzureCloud 615dc844-xxxx-40c2-9db4-0439991ec82e
PS C:\> Test-PartnerDomainAvailability -Domain 'contoso.onmicrosoft.com'
False
PS C:\> Test-PartnerDomainAvailability -Domain 'duybao3.onmicrosoft.com'
True
Conclusion
Regardless of which possibility suits you best, I hope this has been insightful!
Not a reader? Watch this related video tutorial: