Click here to Skip to main content
15,879,535 members
Articles / Hosted Services / Azure
Technical Blog

Remove a Custom Domain from Office 365 - Azure Active Directory

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
5 Feb 2020CPOL 2.8K  
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
This article was originally posted at https://owendavies.net/articles/azure-active-directory

License

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


Written By
Architect
United Kingdom United Kingdom
I have been working in software development for over 16 years, during that time I have worn many hats.

I have worked as a Software Engineer, Architect, Agile Coach and Trainer. I’ve created teams, I’ve lead teams, but my main goal is to help teams build great software and enjoy the process.

I help a whole range of businesses – from startups with just an idea who want to build a team to take that idea into reality and FTSE 100 businesses who need to optimise existing teams – I train, mentor and coach them to success.

If you happen to know of anybody who could benefit from results like this, then please go to my contact page and get in touch.

Owen Davies

Comments and Discussions

 
-- There are no messages in this forum --