DNS. Remove NS Records. Powershell.

After a force removal of a Domain Controller and the metadata cleanup using ntdsutil, I was left with a heap of NS records for each Zone in DNS to remove. Although possible, using the GUI to do this would be painful.

I removed these using Powershell and the DNS cmdlets.

Get-DnsServerZone | %{$Name = $_.zonename ; Get-DnsServerResourceRecord -ZoneName $_.zonename -RRType ‘NS’ | ?{$_.RecordData.NameServer -like “*serverfqdn.domain.com*”} | Remove-DnsServerResourceRecord -ZoneName $name}

Note: This requires confirmation each time. If you are brave enough use the ‘-Confirm:$false’ switch, however I wouldn’t recommend it.

If you want to confirm the records returned are correct, run the command below first

Get-DnsServerZone | %{$Name = $_.zonename ; Get-DnsServerResourceRecord -ZoneName $_.zonename -RRType ‘NS’ | ?{$_.RecordData.NameServer -like “*serverfqdn.domain.com*”}



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