PowerShell: Get Old AD DNS Records

Sometimes Active Directory DNS fails to scavenge and delete old DNS records. You can grab a list of records using PowerShell.

Use this example to grab DNS records from the year 2017. Replace “DCName” with the name of a Domain Controller and “ad.yourdomain.com” with your domain name.

Get-DnsServerResourceRecord -ComputerName DCName -ZoneName "ad.yourdomain.com" -RRType "A" | Where {$_.TimeStamp.Year -eq 2017}

This code will show DNS records older than 14 days.

Get-DnsServerResourceRecord -ComputerName DCName -ZoneName "ad.yourdomain.com" -RRType "A" | Where {($_.Timestamp -le (get-date).adddays(-14)) -AND ($_.Timestamp -like "*/*")}

Leave a comment

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