Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Hosted-services / Azure

Remove a Custom Domain from Office 365 - Azure Active Directory

0.00/5 (No votes)
5 Feb 2020CPOL 3K  
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)