Geeks With Blogs
Kay Sellenrode's Blog

When you face large Office 365 implementations you might need to add many domains, going through the wizard will take up much time.

Recently I had to work through an extensive list of domains as well, so I created a quick few lines of PowerShell that helped me solve this in seconds instead of hours.
Using PowerShell and an input file I added the domains and additional to that got a list of all DNS txt records that were needed to be created.

Here is the PowerShell script: here is the PowerShell script I used

$domains=import-csv .\domains.csv                                                
$txtrecord=@()                                                                
foreach($domain in $domains){                                                    
new-msoldomain -Name $domain.domain                                                
$txtrecord+=(Get-MsolDomainVerificationDNS -DomainName $domain.domain -mode dnstxtrecord)        
}                                                                        
$txtrecord | select-object text,label,ttl | export-csv c:\temp\txtrecord.csv                
            

This will give you a nice CSV file with the required DNS txt records per domain, which you can send to your DNS gurus to do their thing.

As input file I used a CSV file that was built as following:

Domain            
contoso.com        
Tailspintoys.com    
Fabrikam.com        
Contoso.net        
Tailspintoys.net    
Fabrikam.net        
    

Of course you will need the Windows Azure Active Directory Module to do this.
Find more details at: http://technet.microsoft.com/library/jj151815.aspx

 

 

Posted on Thursday, May 8, 2014 11:51 PM | Back to top


Comments on this post: Adding Domains to Office 365 using PowerShell

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
Great post!

Just wanted to add a follow-up to say that after adding the DNS records, we must return to PowerShell to complete verification. Attempting to do so in the Admin Center will throw an error and cause the domain to be removed from the tenant.

Here's a command that can be used to complete the verification:

Get-MsolDomain | Where-Object {$_.Status -eq "Unverified"} | ForEach-Object {confirm-msoldomain -domainname $_.name}
Left by Shabad Chawla on Jan 21, 2016 5:36 PM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
Hi,

any idea what the minimum administration requirements for adding a domain to Office365 are?
Left by Alex on Apr 25, 2016 2:45 PM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
How can I find out the required DNS records for a new domain via powershell? I have added the domain, verified the domain and can now use it to add new users, but need to find out what the MX record is as it's not standard (meaning instead of domain-com.mail.protection.outlook.com, it's something closer to domain-com02b.mail.protection.outlook.com) and I cannot figure out how to pipe that info out via powershell. Any suggestions?
Left by Tom Erdely on Jul 18, 2017 7:47 PM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
This PowerShell code text template is what I was missing in the assignment that I had to prepare for my computer applications class.
I’m not too sure about the CSV file, though, because that didn’t work for me earlier and I had to ask someone else to write my paper for me.

Left by Yelena Smith on Dec 14, 2017 9:28 AM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
function Get-Office365MXtoken($domain){
$delimiter=0
$token=$domain
$hyphenReplaceToken=""
$chunkSize=4
$chunks=@()
$startindex=0
do{
if($startindex+ $chunkSize -gt $token.Length){
$chunkSize=$token.Length-$startindex
}
$chunks+=$token.Substring($startindex,$chunkSize)
$startindex+=$chunkSize
}until($startindex -gt $token.Length -or $chunkSize -le 1)
[int]$chunkSize=4
[int]$skipCount=0
[int]$intOfA=[int][char]'a'
foreach($chunk in $chunks){
$digit=$intOfA
for($i=0; $i -lt $chunkSize;$i++){
if("-" -eq $chunk[$i]){
$digit+=[math]::Pow(2,$i)
}
}
if($intOfA -eq $digit){
$skipCount++
}else{
if($skipCount -ne 0){
$hyphenReplaceToken+=$skipCount
}
$hyphenReplaceToken+=[char][int]$digit
$skipCount=0
}
}
if($hyphenReplaceToken.length -gt 0){
$token+=[string]$delimiter+[string]$hyphenReplaceToken
}
$token=$token.Replace("-","")
$token=$token.Replace(".","-")
return "$token.mail.protection.outlook.com"
}
Left by SK on Dec 22, 2017 9:06 PM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
Nice blog the blog is very informative to keep sharing all this type of information it's really helpful content quality is unique and fresh
active HostGator promo codes
Left by calvin on Feb 06, 2018 1:46 PM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...

Mind boggling post. I discovered your site ideal for my necessities. To an awesome degree essential data particularly the last part. Grateful to you for providing for us, and we truly trust you will keep reviving or post unmistakable articles
newintrends

women fashion trends
Left by newintrends on Apr 11, 2018 7:11 AM

# re: Adding Domains to Office 365 using PowerShell
Requesting Gravatar...
You will always get to find many unique and things that are found in the Kroger Store. check below for detailed info on kroger feedback
Left by kroger feedback on May 28, 2018 8:03 AM

Your comment:
 (will show your gravatar)


Copyright © Kay Sellenrode | Powered by: GeeksWithBlogs.net