Domain Controller DNS Records can be cleaned up with Powershell.
At Bobcares, we often handle similar requests from our customers as part of Server Management Services.
Today let’s see how our Support Engineers do this with the help of Powershell.
How to Clean up Domain Controller DNS Records?
One method that our Support Techs follow is to clean up Stale/Dead Domain Controller records by using PowerShell.
We know that Windows 7 and all orther later version usually have PowerShell.
Steps to follow are given below:
1. First, we create an array of all the records in the zone _msdcs.bob.com:
$dnsrecords = Get-DnsServerResourceRecord -ZoneName “_msdcs.bob.com”
The data we filter is part of the ‘RecordData’ data column which is inside an array and an array of data itself.
2. Next, we can separate the Domain Controller(DC) for clean up. And for doing this we have to filter the resulting data
We can filter this data depending upon some of the attributes such as IPv4Address, NameServer, and DomainName which are available in the RecordData recordset.
$deadDC = $dnsrecords | Where-Object {$_.RecordData.IPv4Address -eq “192.168.50.15” -or $_.RecordData.NameServer -eq “DC02.bob.com.” -or $_.RecordData.DomainName -eq “DC02.bob.com.”}
3. Once this is complete we have all the DNS records for dead Domain Controller in an array.
Usually, it is easy to delete them all. And this can be done simply by calling the Remove-DnsServerResourceRecord cmdlet against the array and the zone.
$deadDC | Remove-DnsServerResourceRecord -ZoneName “_msdcs.bob.com” -whatif
4. We must ensure that we do not delete anything of relevance. All we have to do is simply remove the ‘whatif’ since this will delete the record.
Generally, after doing this there will not need a manual clean-up.
So, can bring all those components into one command to get the following result:
Get-DnsServerResourceRecord -ZoneName “_msdcs.bob.com” | `Where-Object {$_.RecordData.IPv4Address -eq “192.168.50.15” ` -or $_.RecordData.NameServer -eq “DC02.bob.com.” -or `$_.RecordData.DomainName -eq “DC02.bob.com.”} | Remove-DnsServerResourceRecord -ZoneName “_msdcs.bob.com” -force
[Need assistance to clean up domain controller records? We can help you!]
Conclusion
To conclude, we saw how our Expert Support Engineers clean up Stale/Dead DC DNS records with the help of PowerShell.
Also, we saw how easy it is to clean up domain controller records with the help of this method using few Windows PowerShell commands.
0 Comments