Skip to main content

Office365: Cannot remove custom domain

When you need to remove one of your custom domains from Office 365 you can find that you cannot do this.
One of possible issues with this is when you are working in hybrid environment and if you have DirSync working which synchronizes your AD to the Microsoft cloud.
This is one of undocumented behaviors of Office 365, that you cannot remove domains, i.e. not all of them, cause I have just done this without problems with some, but still cannot do this with others.

When I have searched for resolution on Office365 Community and other Google sites and blogs, I found nothing than "Before you remove a domain name from Office 365, you have to remove anything that is using the domain name":
http://office.microsoft.com/en-us/office365-suite-help/remove-a-domain-HA102818535.aspx

Fortunately, if you are working in hybrid environment, the shorter path exists.

First login to your Office 365 tenancy from powershell:
Connect-MSolService

Run:
Get-MsolUser -DomainName yourdomainname.com

If you get some entries here, then you have to disable this users licences in Office365 panel

If now Get-MsolUser -DomainName yourdomainname.com gives you empty return, then you can go further. If not, you have to disable licences assigned to users with your domain e-mail addresses.

After getting empty result for Get-MsolUser -DomainName yourdomainname.com , you can

Run:
Get-MsolGroup -All | where {$_.proxyaddresses -match "yourdomainname.com"}

You probably see some entries here.
You will need to remove addresses with your domain aliases from those groups.
If your company have dirsync configured, then you will need to remove those aliases from AD.
If you are running hybrid confirutation, with Exchange on-premises, you can remove those aliases from Exchange side.

After removal wait about 15 minutes, force DirSync synchronization and check on the Office 365 side, again running the:
Get-MsolGroup -All | where {$_.proxyaddresses -match "yourdomainname.com"}

If, finally you will get empty result, you can remove the domain from Office 365 side.

Wish you luck!