When you manage an email system, you’re sure to deal with MX records, and sometimes it is good to be able to generate a report of all the DNS MX Records for your domains to monitor their validity or availability. Being caught by surprise as your MX records go missing resulting in incoming mail delivery failures is never good.
This script can query a list of domains for their MX records, and generate a report which can be also sent as an email. Depending on your purpose, you can just run it manually or setup a task to run the script at an interval or daily schedule.
https://github.com/junecastillote/Get-MXReport
Install-Script Get-MXReport –Scope AllUsers
Once completed, the script will be installed in “C:\Program Files\WindowsPowerShell\Scripts” by default, and is added to the PATH.
This example queries the MX record for the specified domains and save the HTML and CSV report to the specified folder
This example queries the MX records, save the reports to the specified folder and if a failed lookup is logged, it will send the email report to the specified recipient using a non-authenticated SMTP relay and the CSV report is attached to the email.
This example queries the MX records, save the reports to the specified folder and if a failed lookup is logged, it will send the email report to the specified recipient using an authenticated SMTP relay via Office 365, port 587 with SSL.
This script can query a list of domains for their MX records, and generate a report which can be also sent as an email. Depending on your purpose, you can just run it manually or setup a task to run the script at an interval or daily schedule.
Requirements
This script requires PowerShell version 5.1How to Install
From GitHub Repository
You can download the latest version of the script from this link, and just save it in you preferred folder.https://github.com/junecastillote/Get-MXReport
From PS Gallery
This script can be installed from PSGallery by running this command:Install-Script Get-MXReport –Scope AllUsers
Once completed, the script will be installed in “C:\Program Files\WindowsPowerShell\Scripts” by default, and is added to the PATH.
How to Use
Get-MXReport.ps1 [-domains] <string[]> |
Examples
EXAMPLE 1
Get-MXReport.ps1 –domains “gmail.com”,”lazyexchangeadmin.com” –outputDirectory C:\Scripts\output |
EXAMPLE 2
$domainsList = “gmail.com”,”yahoo.com”,”lazyexchangeadmin.com”
Get-MXReport.ps1 –domains $domainsList –outputDirectory C:\Scripts\output –sendEmail OnError –sender sender@domain.com –recipients recipient1@domain.com,recipient2@domain.com –smtpServer smtp.server.com –smtpPort 25 –AttachCSVReport
|
EXAMPLE 3
$domainsList = “gmail.com”,”yahoo.com”,”lazyexchangeadmin.com”
$smtpCredential = (Get-Credential)
Get-MXReport.ps1 –domains $domainsList –outputDirectory C:\Scripts\output –sendEmail OnError –sender sender@domain.com –recipients recipient1@domain.com,recipient2@domain.com –smtpServer smtp.office365.com –smtpPort 587 –smtpSSL –AttachCSVReport –smtpServerRequiresAuthentication –smtpCredential $smtpCredential
|
Required Parameters
-domains- Type: String (multiple, array)
- Description: List of mail domains to query.
- Example: “contoso.com”,”gmail.com”
- Type: String (directory path)
- Description: Path to where the reports will be saved.
- Example: C:\scripts\report
Optional Parameters
-nameServer- Type: String
- Description: Name or IP of the custom DNS Server to use for lookup. If not specified, script will use the local DNS Server IP of the machine.
- Example: “8.8.8.8”
- Type: String
- Description: Path to where the session transcript log should be saved. Logging will only work if this is specified.
- Example: C:\scripts\log
- Type: String
- Description: String that will appear in front of the report title or email subject. Can be any string value.
- Example: MyCompanyName
- Type: String
- Valid values:
- Always – Send email report everytime.
- OnError – Send email report only when there’s a failed lookup result.
- Description: If specified, the script will trigger sending of the report through email.
- Example: –sendEmail Always, –sendEmail OnError
- Type: String
- Description: The email address that will appear as the sender of the email
- Example: sender@domain.com
- Type: String
- Description: The recipient address or addresses of the email report. This parameter is required if -sendEmail is used.
- Example: recipient1@domain.com,recipient2@domain.com
- Type: String
- Description: The IP address, Hostname, or Fully-Qualified Domain Name of the SMTP Relay Server. This parameter is required if -sendEmail is used.
- Example: smtp.server.com
- Type: Integer
- Description: The SMTP Port Number to be used along with the –smtpServer. This parameter is required if -sendEmail is used.
- Example: 25
- Type: Switch
- Description: Use if the SMTP server requires authentication to be able to relay messages. There is no need to specify any value for this parameter.
- Type: PSCredential
- Description: The login credential for the SMTP server authentication. This parameter is required if -smtpServerRequiresAuthenticationis used.
- Example: $smtpCredential = Get-Credential
- Type: Switch
- Description: Use this switch if the SMTP Relay connection requires SSL.