There may be times when you need to add tens or even hundreds of domains to an Office 365 tenant so using the GUI isn’t really an option.

I’ve created a little script here that will make this process easier.

It takes a csv file (called domains.csv) that exists in the same folder as the script itself and outputs the domain proof required for each domain to a domains.log text file.


The CSV file must be a single column csv file in the following format;


I’ve included a generic domain CSV file in the downloadable zip archive if that’s easier for you.

write-host ——————————————–
write-host Authenticating….
write-host ——————————————–
Import-Module MSOnline
$cred = Get-Credential
Connect-MsolService -Credential $cred
$count=import-csv .\domains.csv | measure
$domainlist=import-csv .\domains.csv
write-host ——————————————–
write-host Importing $count.count Domains….
write-host ——————————————–
Function LogWrite {
Param ([string]$logstring)
Add-content $logfile -value $logstring
logwrite “Domain,TXTRecord”
foreach ($domain in $domainlist)
New-MSOLDomain -name $domain.domain
$proof = (Get-MSOLDomainVerificationDNS -domainname $domain.domain | select-object -expandproperty label).split(“.”)[0]
$txtrecord=”MS=” + $proof
logwrite “$domainrecord,$txtrecord”

Leave a Reply

Your email address will not be published. Required fields are marked *