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

Firstly, run powershell as Administrator and execute
[powershell]Import-Module DnsClient[/powershell]

After that you can run the Resolve-DnsName cmdlet:
[powershell]
Resolve-DnsName reddit.com
[/powershell]

Which returns:
resolve-dnsname

You can specify which type of record you’re interested in:
[powershell]
Resolve-DnsName -type MX reddit.com
[/powershell]

resolve-dnsname-mx

So, take that logic and add a sprinkle of basic string functions to get:
[powershell]
(-join (Resolve-DnsName -Type MX –Name reddit.com -ea 0).NameExchange).ToLowerInvariant().Contains("google")
[/powershell]

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 *