Check commmon records for a domain

Check commmon records for a domain

  •  
  •  
  •  
  •  
  •  
  •  

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
  • CNAME
  • MX
  • TXT (for SPF)
  • TXT (for DMARC)

This is what I came up with, so maybe it can help someone else. ūüôā

param (
 [array]$Name,
 $NameServers = @('8.8.8.8','4.2.2.2')
)

$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
}
$ResolvedData

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.

Leave a Reply

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