Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's Office 365 Admin Blog > Posts > How to Add a Domain to Office 365 and Azure using PowerShell
January 17
How to Add a Domain to Office 365 and Azure using PowerShell

I love blog posts like this. PowerShell and Office 365, two of my favorite tastes, all rolled up into one. This particular blog post is not groundbreaking, but it’s fun. I’ve recently set up a few Office 365 tenants, and part of that is adding one or more custom domains. Of course you can use the Office 365 Admin Portal to do that, and there’s no shame in that. (Well, maybe a little) But if you want to take your Office 365 Admin game up another level, you can do all of that with PowerShell. I’ll show you how in this blog post.

Getting the Module and the Domain

You need to make sure you have the correct Azure PowerShell module installed before you can take advantage of any of the goodness in this blog post. When I wrote this blog post, I was using version of the MSOnline module. If you don’t have it installed, you can watch Shane’s crappy video walkthrough on installing it. Time marches on, and it marches double-time in the cloud. So while I assume these steps will work later versions of the module, I can’t guarantee that.

To add a domain to your Office 365 tenant, you’ll obviously need a domain. It doesn’t matter where you register the domain, as long as you have the ability to add DNS records. Microsoft does have a deal in place with GoDaddy, so getting your domain there does have some advantages.

Adding the Domain

Once you have the module installed, and the domain purchased it’s time to open up PowerShell and make some magic. Open up “Microsoft Azure Active Directory Module” to get the party started. I christen every PowerShell session with a heaping helping of Start-Transcript, so do that first. Then use Connect-MsolService to connect to your tenant. If you haven’t already added a custom domain to your Office 365 or Azure tenant, then you’re likely logging in with a username that looks like, where sometenant is your tenant name, and someone is a tenant admin for that tenant. To get the landscape of the domains in your tenant, use Get-MsolDomain. It looks like this:


Once you’ve confirmed the domain you want to add isn’t already there you can use New-MsolDomain to add it. The command I ran was 

New-MsolDomain -Name ""

It might seem like that should be enough. The domain is added, Ta-Da! If that was the case, this would be a very short blog post. We still have a couple of steps left. I have to prove to Microsoft that I own Maybe is Todd Rundgren’s blog, or maybe Todd Bridges. Who knows? To verify that I am truly the Todd behind, I have to make a specific DNS entry that Microsoft tells me to add.

Before I can add the correct DNS entry, I need to know what it is. The Get-MsolDomainVerificationDns gives me that value. We have two options, we can create a TXT record, or an MX record. Since I’m not moving the mail for over to Office 365 right now, I went with the TXT record. If I was moving mail in the short term, I would have went for the MX record instead, and saved myself the step of adding it later. To get the TXT record I need, I ran this command:

Get-MsolDomainVerificationDns -DomainName -Mode DnsTxtRecord

Here is the output I received:


I used GoDaddy’s domain management tool to add this record. While the label in the screenshot says “” I really needed to add a record for @, which tells DNS clients “this domain.” It looked like this:


DNS takes its time to move around the Internet, and it gets cached a lot of places along the way. To improve the chances that Microsoft gets the new record, I used nslookup to query a major DNS provider, Google, and make sure it was there:

nslookup -type=TXT

I got the output I expected:


Looks good.

The final step is telling Microsoft to check that we made the entry, and made it correctly. Let’s see what happens:

Confirm-MsolDomain -DomainName

The output looks like I did it right.


Let’s check our list of domains again with Get-MsolDomain



More good news. And finally, in the UI:


The domain shows up as “Setup in progress” because I haven’t added all the DNS records Office 365 needs to send email and stuff like that. The domain is still good though. I can assign that domain to users. It’s fully functional.

To recap, here was the whole process:

New-MsolDomain -Name ""

Get-MsolDomainVerificationDns -DomainName -Mode DnsTxtRecord

Confirm-MsolDomain -DomainName

The other stuff was just fun fluff.

I hope this helps, and encourages you to get your PowerShell on when working with Office 365 and Azure.



Edit: Fixed link to MSOnline Module download


ShortURL broken

 on 3/16/2018 3:34 PM

Re: ShortURL broken

Right you are. Thanks for the heads up. It's fixed now.

Todd O. KlindtNo presence information on 3/22/2018 9:42 AM

Re: How to Add a Domain to Office 365 and Azure using PowerShell

I found this useful.  Thanks for this.
 on 7/8/2019 3:24 PM


Explore a world of mind bending Trippy art, unique decor, and immersive experiences Discover captivating designs that ignite your senses and redefine creativity UV party
 on 10/3/2023 8:47 AM


the actually great website. the realy informative plus a this kind of excellent career. i enjoy this kind of. kitchen renovation
 on 10/4/2023 4:41 AM


You happen to be permitted to article labels, and not backlinks, until these are accredited along with in theme. 먹튀검증
 on 10/9/2023 7:13 AM


As i pleased considering the studies one which is designed to get this individual print remarkable. Splendid actions! 토토사이트
 on 10/9/2023 8:27 AM


Concerning a short while ago going your site, the information you actually give on this site includes made it simpler for people considerably. With thanks to get your complete time frame & deliver the results. 메이저카지노
 on 10/16/2023 3:34 AM


 on 10/18/2023 4:06 PM

buggy ride dubai

I can’t imagine focusing long enough to research; much less write this kind of article.  You’ve outdone yourself with this material.  This is great content. <a href="">buggy ride dubai</a>
 on 10/19/2023 2:41 AM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.


Body *

Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person


Want a message when I reply to your comment? Put your Twitter handle here.