Checking if a domain’s mail server is actually Gmail using Powershell

Firstly, run powershell as Administrator and execute

Import-Module DnsClient

After that you can run the Resolve-DnsName cmdlet:

Resolve-DnsName reddit.com

Which returns:
resolve-dnsname

You can specify which type of record you’re interested in:

Resolve-DnsName -type MX reddit.com

resolve-dnsname-mx

So, take that logic and add a sprinkle of basic string functions to get:

(-join (Resolve-DnsName -Type MX –Name reddit.com -ea 0).NameExchange).ToLowerInvariant().Contains("google")

Which returns True/False if any of the MX records contain “google”, which would mean the mail server is Gmail.

Leave a Reply

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