65.9K
CodeProject is changing. Read more.
Home

Remove a Custom Domain from Office 365 - Azure Active Directory

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Feb 5, 2020

CPOL
viewsIcon

3001

This post will show you how to remove a custom domain from Office 265 using Azure Active Directory.

I was setting up a custom domain within Azure. After I added the TXT record to our DNS to verify ownership, it gave me the following error message.

To do this in PowerShell, we’re going to install the Azure ActiveDirectory (MSOnline) Module:

install-module MSOnline

Connect-MsolService:

Connect-MsolService

Remove-MsolDomain:

Remove-MSolDomain -DomainName safetonet.com

I was greeted with the following error.

I then ran the Get-MsolUser command as the error suggested.

Get-MsolUser -DomainName safetonet.com

But this returned nothing.

You need to remove the users, groups and XXXX before being able to remove the domain.

View and Remove Groups

Within the Office 365 portal, I wasn’t able to delete the group that existed for the domain.

View Groups

But by running the Get-MsolGroup command, I can see all the groups in the account:

Get-MsolGroup

I can see the group that exists within the domain, and can take note of the objectid to use with the remove command Remove-MsolGroup.

Remove the Group Object

Remove-MsolGroup -Objectid '9b1aer67-11x4-4398-b8cb-330b923f3016'

Delete the Domain

Now we have deleted all the resources in the domain. We can again use the Remove-MsolDomain command to delete our Domain.

Remove-MSolDomain -DomainName contoso.com