×


Clean up Domain Controller DNS Records with Powershell

Metadata cleanup is a required procedure after a forced removal of Active Directory Domain Services (AD DS).

Domain Controller DNS Records can be cleaned up with PowerShell.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform  DNS related configurations.

In this context, we shall take a look at how to use PowerShell to Clean up Domain Controller DNS Records.


How to Clean up Domain Controller DNS Records?

By using PowerShell, you can clean up Stale/Dead Domain Controller records.

Windows 7 and all other later version of Windows OS usually ships PowerShell by default.


Follow the steps below to Clean up Domain Controller DNS Records;


1. First, we create an array of all the records in the zone _msdcs.ibmimedia.com:

$dnsrecords = Get-DnsServerResourceRecord -ZoneName “_msdcs.ibmimedia.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.ibmimedia.com.” -or $_.RecordData.DomainName -eq “DC02.ibmimedia.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.ibmimedia.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.ibmimedia.com” | `Where-Object {$_.RecordData.IPv4Address -eq “192.168.50.15” ` -or $_.RecordData.NameServer -eq “DC02.ibmimedia.com.” -or `$_.RecordData.DomainName -eq “DC02.ibmimedia.com.”} | Remove-DnsServerResourceRecord -ZoneName “_msdcs.ibmimedia.com” -force


[Need urgent assistance to clean up domain controller records?  We can help you! ]


Conclusion

This article will guide you on the process to clean up Stale/Dead #DC DNS records with the help of #PowerShell. You can see that it is easy to clean up domain controller records with the help of this method using few Windows PowerShell #commands.

To remove old DNS records from a domain controller, simply Remove #DNS Entries by:

1. Right click a #Zone in DNS console and go to properties, Under Name server tab delete the entries that are related to decommissioned DC.

2. Open DNS Console and Remove the IP of the decommissioned DC that might be present on the #network #adapter.