DNS PTR record checking

I was recently asked how to find the missing PTR records…. so here it goes – 1st draft.

#Check records on DNS server itself.
$DNSsvr='YourDNS'
$DNSAZone='Your Main A Zone FQDN here'
$DNSrecords=Get-DnsServerResourceRecord -ZoneName $DNSAZone -ComputerName $DNSsvr -RRType A
$DNSrecords | ForEach-Object {
$dnsobj = $_
$IPsplit=(($dnsobj.RecordData).IPv4Address.IPAddressToString -split "\.")
$PTRZone=$IPsplit[2]+'.'+$IPsplit[1]+'.'+$IPsplit[0]+'.in-addr.arpa'
try
{
$CHK1=Get-DnsServerZone -ComputerName $DNSsvr -Name $PTRZone -ErrorAction Stop
$errorvar = '0' 
}
catch
{
Write-host "Unable to find a reverse lookup zone for" $PTRZone "for record" ($dnsobj.HostName)
$errorvar = '1'
}
if ($errorvar -ne '1')
{
 try
 {
 $RevDNSrecords=Get-DnsServerResourceRecord -ZoneName $CHK1.ZoneName -ComputerName $DNSsvr -RRType Ptr -Name $IPsplit[3] -ErrorAction Stop
 $errorvar= '0'
 }
 catch
 {
 Write-Host "Unable to find a record for" ($dnsobj.HostName) "in" $PTRZone
 $errorvar='1'
}
 }
 else
 {
 }
Clear-Variable -Name CHK1
}

 

Advertisements

Author: Hyper-Vine

Microsoft Certified Solutions Expert - Cloud Platform & Infrastructure System Center Admin - 2007, 2012 & 2016 Infrastructure Consultant

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s