Powershell – Use PowerShell to obtain Office 365 DNS records

domain-name-systemmicrosoft-office-365mx-recordpowershell

For the past while, I’ve been learning PowerShell to administrate our Office 365 tenancy instead of using the web interface.

After adding a new domain and confirming ownership of the domain name (all done through PowerShell), I was wondering if there’s a cmdlet that can be used to obtain the zone records that should be configured for a domain that is to be managed by Office 365.

Gather the information you need to create Office 365 DNS records explains how to obtain this information using the web interface but I’d prefer to do as much as possible using PowerShell.

At the moment, I can use the Get-DkimSigningConfig to determine the correct CNAME record to enable DKIM, e.g.,

Get-DkimSigningConfig -Identity contoso.com | fl Selector?CNAME

This should generally be of the form selector1-contoso-com._domainkey.contoso.onmicrosoft.com but I found that for one of our managed domains the DKIM CNAME had to be set to selector1-contoso-com0i._domainkey.contoso.onmicrosoft.com (an additional 0i).

For the MX record, I’d expect it to be contoso-com.mail.protection.outlook.com but I’d like to be certain so I’m wondering if there’s a PowerShell cmdlet or Azure object that lists the DNS records that should be configured for a managed domain (in particular what to use for the MX record).

I spent a lot of time searching the web and Microsoft’s own documentation but I only found references to how to determine this information using the web interface.

Best Answer

A little bit late, but for future reference, this is now possible using the AzureAD module:

Get-AzureADDomainServiceConfigurationRecord -Name mydomain.com

Or if you want to get only the MX record:

(Get-AzureADDomainServiceConfigurationRecord -Name mydomain.com | `
           where RecordType -eq MX).MailExchange

You can also set the supported services for a newly added domain using:

Set-AzureADDomain -Name mydomain.com -SupportedServices Email, OfficeCommunicationsOnline, Intune
Related Topic