All,
As I head through a major refresh I realized it was way too cumbersome to manually remove decommissioned domain controllers from the 'Name Servers' tab inside of DNS forward and reverse lookup zones. I came up with the below script to automate the removal of these records. I hope this helps others in the future.
All you need to do is modify the FQDN (Fully Qualified Domain Name) on Line 2.
As I head through a major refresh I realized it was way too cumbersome to manually remove decommissioned domain controllers from the 'Name Servers' tab inside of DNS forward and reverse lookup zones. I came up with the below script to automate the removal of these records. I hope this helps others in the future.
All you need to do is modify the FQDN (Fully Qualified Domain Name) on Line 2.
Code:
#FQDN of the domain controller that has been decommissioned or is offline
$oldDMCName = "DMC1.domain.org"
#Get the PDC Emulator
$PDCe = Get-ADDomainController -Discover -Service PrimaryDC
#Get all DNS zones on the PDCe
$DNSZones = Get-DnsServerZone -ComputerName $PDCe
#Iterate DNS zones and remove the stale domain controller record where applicable
ForEach($zone in $DNSZones)
{
$zone = $zone.zoneName
$getZoneInfo2 = (Get-DnsServerResourceRecord -ZoneName $zone -Name "@" -RRType NS -ComputerName $PDCe).recorddata.nameserver
If($getZoneInfo -like "*$oldDMCName*")
{
Try
{
Remove-DNSServerResourceRecord -ZoneName $zone –Name “@” –RRType NS –RecordData $oldDMCName -ComputerName $PDCe -Force
}
Catch
{
Write-Output "Error removing $oldDMCName from $zone"
}
}
Else
{
Write-Output "$oldDMCName does not exist in zone $zone"
}
}
Comment