Add Office 365 Domain using PowerShell
In this post, I will look at how to add a new Office 365 Domain using PowerShell.
Before we start with adding the domain we need to make sure that we have the following information available.
- Tenant ID
- FQDN of the new Domain you want to add
- The FQDN must be registered with a DNS registrar
- You need to know how to add a TXT record to the Registered DNS zone with the registrar
To get started, we need to establish a connection to Microsoft Office 365. This can be done using the following script posted on TechNet. https://gallery.technet.microsoft.com/office/Connect-To-Office-365-9b235018
Or use the following method
1 |
$UserCredential = Get-Credential |
1 |
Connect-MsolService -Credential $UserCredential |
Once you have provided your login details run the following cmdlet to establish the connection.
1 |
Connect-MsolService |
Once the connection has been established, let’s verify the current Domains in the Tenant by running the following cmdlet.
1 |
Get-MsolDomain |
Before we can go ahead and add the new domain we need to find out what the Office 365 tenant ID is, this can be found running the following cmdlet.
1 |
Login-AzureRmAccount |
Now that you have the Tenant ID, let’s go ahead and create create the new domain using the following cmdlets.
1 |
New-MsolDomain -TenantId f8a9f5a5-fbb5-9f67-84b9a9f74 -Name ThatLazyNerd.com |
New Domain has been added successfully
As we can see the status of the domain is still as Unverified, so our next step is to complete the verification process.
The following cmdlet will return the DNS TXT record details which needs to be added to your domain DNS records.
1 |
Get-MsolDomainVerificationDNS -TenantId f8a9f5a5-fbb5-4c50-9f67-84b1899a9f74 -DomainName ThatLazyNerd.com |
We need to use the following details from the output.
- Label
- Txt
- Tlt
This is what the TXT record will then look as follow.
Now that the new record has been created with the Domain hosting provider, let’s go ahead and verification that the new TXT record has been created.
Now that we have our record created and verified, let’s go ahead and complete the domain verification process.
The verification process can be completed by running the following cmdlet.
1 |
Confirm-MsolDomain -TenantId f8a9f5a5-fbb5-4c50-9f67-84b1899a9f74 -DomainName ThatLazyNerd.com |
Let’s go ahead and run the following cmdlet again to view all verified domains in the tenant.
1 |
Get-MsolDomain |
As we can see the newly added domain has been added and verified as well.
To sum it up, in this post we have covered how to add a new domain to Office 365 using PowerShell.
#ThatLazyAdmin
Be First to Comment