(Cloud) Tip of the Day: Use PowerShell to check domain availability for Office 365 and Azure


Today’s Tip…

To extend a previous tip on checking domain availability even further, one could use the following PowerShell function to check the domain name availability:

 

function Test-DomainAvailability {

      param(

             [Parameter(mandatory=$true)]

             [string]$DomainName

       )

       $descriptions = @{

              Unknown   = ‘Domain does not exist in Office 365/Azure AD’

              Managed   = ‘Domain is verified but not federated’

              Federated  = ‘Domain is verified and federated’

       }

      $response = Invoke-WebRequest -Uri “https://login.microsoftonline.com/getuserrealm.srf?login=user@$DomainName&xml=1

     if($response -and $response.StatusCode -eq 200) {

           $namespaceType = ([xml]($response.Content)).RealmInfo.NameSpaceType

           New-Object PSObject -Property @{

                    DomainName = $DomainName

                    NamespaceType = $namespaceType

                    Details = $descriptions[$namespaceType]

           } | Select-Object DomainName, NamespaceType, Details

    } else {

        Write-Error -Message ‘Domain could not be verified. Please check your connectivity to login.microsoftonline.com’

    }

}

Usage examples:

Test-DomainAvailability -DomainName WILLFID.MSFTONLINEREPRO.COM

Test-DomainAvailability -DomainName WILLIAMFIDDES.COM

Test-DomainAvailability -DomainName FAKEDOMAIN.COM

Comments (1)

  1. Domain and range errors are both used when dealing with mathematical function

Skip to main content