Gathering MX Records for Office 365 Domains

I have come across the need for a simple output of MX records for each domain in an Office 365.

An Office 365 tenant can contain multiple domains in a verified or unverified state.

This script simply outputs the MX records for each domain that has been verified into a CSV file named after the tenant ID.  The CSV file is output to the %temp% by default.

You will need to run the script inside a PowerShell session connected to Office 365.



#This script collects the MX records for all domains which have been verified in an O365 tenant.
#Run the script from within an O365 PowerShell session.
#Author: Ben Owens
#Date: 03/10/2016

$temp = $env:temp
$TenantID = Get-MSOLDomain | Where {$_.IsInitial -eq "TRUE"} | Select Name -ExpandProperty Name
$Domains = Get-MSOLDomain | Where {$_.Status -eq "Verified"} | Select Name
$MXRecords = ForEach ($Domain in $Domains) {Resolve-DnsName -Name $Domain.Name -Type MX | Where {$_.QueryType -eq "MX"}}
$MXRecords | Export-CSV "$Temp\$TenantID-mxrecords.csv" -NoTypeInformation
$Output = "$Temp\$TenantID-mxrecords.csv"
$Output
Notepad $Output

Example Output:

Comments

  1. The information in the post you posted here is useful because it contains some of the best information available. office 365 business plans. Thanks for sharing it. Keep up the good work.

    ReplyDelete

Post a Comment

Popular posts from this blog

Assigning Windows 10/11 Enterprise Subscription Activation Licences to Hybrid Azure AD Joined Devices

Power Automate: Get first item in output

De-selectable radio buttons - Power Apps