During a recent migration I encountered an issue deleting a domain from O365 and Azure.  In the Microsoft 365 admin center, it displayed some items to remove such as SMTP addresses, SIP, and distribution groups tied to the domain.  After all these items were cleaned up in Active Directory it still would not remove and the portal GUI gave a generic error.  To display ALL items I needed to do the following:

Connect to Azure AD:

  1. Launch PowerShell as Administrator.
  2. Install the module for Azure AD:
    Install-Module -Name MSOnline
  3. Connect to your Azure AD and Login:
    Connect-MsolService
  4. Run the following command to find anything tied to the domain in question:
    Get-MsolUser -DomainName contoso.com -MaxResults 8000

You will now need to use the results to cleanup any SMTP addresses, SIP addresses, Groups etc tied to the domain.  NOTE: Some groups may be cloud only groups and I also had an issue in which some accounts were moved to an OU no longer synced with AD Connect.  These also needed to be corrected and the changes then synced up to O365.

Remove the Domain:

The domain should now be able to be deleted in the portal or with the command:

Remove-MsolDomain -DomainName "contoso.com" -Force