Check commmon records for a domain

Check commmon records for a domain

3.5 / 5 ( 4 votes )

One of my peers this week was looking for a script to help check global DNS resolution for particular records for both replication and geo-loadbalancing testing.

The record types and data he was looking for:

  • A
  • MX
  • TXT (for SPF)
  • TXT (for DMARC)

This is what I came up with, so maybe it can help someone else. 🙂

param (
 $NameServers = @('','')

$global:ResolvedData = @()
foreach ($Server in $NameServers)
 foreach ($obj in $Name)
  $ARecordData = Resolve-DnsName -Name $obj -Type A -Server $Server -ea silentlycontinue
  $CNAMERecordData = Resolve-DnsName -Name $obj -Type CNAME -Server $Server -ea silentlycontinue
  $MXRecordData = Resolve-DnsName -Name $obj -Type MX -Server $Server -ea silentlycontinue
  $TXTRecordData = Resolve-DnsName -Name $obj -Type TXT -Server $Server -ea silentlycontinue
  $DMARCRecordData = Resolve-DnsName -Name selector1._domainkey.$obj -Type TXT -Server $Server -ea silentlycontinue
  $RecordData = [ordered]@{
   Hostname    = $obj
   Server     = $Server
   A      = $ARecordData.IPAddress -join ","
   CNAME     = $CNAMERecordData.NameHost -join ","
   MX      = $MXRecordData.NameExchange -join ","
   SPF      = $TXTRecordData.Strings -match "v=spf1"
   DMARC     = $DMARCRecordData.Strings
 $Record = New-Object PSobject -Property $RecordData
 $global:ResolvedData += $Record

Copy/save to a .ps1, and then run with -Name (to specify the host or domain you want to check) and -Servers to specify which DNS servers you want to use for resolution.

Then, you can use the variable $ResolvedData to check and see what you’ve got, export to a CSV, filter, or whatever you so desire.


Published by Aaron Guilmette

Helping companies conquer inferior technology since 1997. I spend my time developing and implementing technology solutions so people can spend less time with technology. Specialties: Active Directory and Exchange consulting and deployment, Virtualization, Disaster Recovery, Office 365, datacenter migration/consolidation, cheese. View all posts by Aaron Guilmette

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Exit mobile version