Wednesday 10 August 2016

Remove Office 365 Domain with Force

After working with Office 365 for almost 3 years I have finally decided to get (and pay for) my own tenancy. I am sick of rebuilding O365 tenancies for demo's and testing every time the 30 day trial runs out. With my new "legit" tenancy I can permanently have ADFS etc configured for my lab domain.
Over the last 18 months I have probably had 10 different O365 tenancies for different customer proof of concepts. For these to be successful you often need a unique domain name, of which I own plenty. I tried to configure my "" domain to my new tenancy and received an error as it was currently associated with another tenancy.
The process of removing the old domain is straight forward, if you have access to the old tenancy.
1. Change the primary domain
Set-MsolDomain -Name "" -IsDefault
You must set the domain to the default for your tenancy, otherwise you will get an error when you try to remove your unique domain name.
2. Review which users currently use the unique domain
Get-MsolUser -DomainName ""
This command will show you all the users that are currently using the unique domain you are trying to "seize".
3. Remove any users currently using the domain
Remove-MsolUser -UserPrincipalName -Force
If any user accounts have your domain configured to be their primary UPN suffix, you must first either delete the user or change their UPN to the domain. If you have user accounts synced from Active Directory this command will not work for they accounts.
In my old tenancy the AD Sync was completely blown therefore I could not make the changes in AD. To get around this problem manually set the synced user accounts back to the domain.
4. Remove the unique domain from O365
Remove-MsolDomain -DomainName "" -Force
This command will actually remove the unique domain from the O365 tenancy. If you are trying to bind the domain to another O365 there can be some latency in the O365 service realizing that you have removed it from an old tenancy.