Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Remove Old Name Servers from reverse lookup zones in DNS- PowerShell

$
0
0

Hello Scripting Guys,

I'm a long-time fan. Please let me know if I have included enough information for you to provide some guidance. Thank you!

Here is what I am attempting to do:

import a .csv file which containszoneName,hostname,RecordTypeand then delete the name server entries from the reverse lookup zones.

Why:

There are hundreds of zones and 80+ name servers in each for a total of about 25,000 records to be removed. I have the list of zones and the list of name servers which I want to remove from the zones.

Environment:

I am running PowerShell as a Domain Admin with access to DNS. Zones allow secure updates only (if that matters here). I am running it from a Server 2012 R2 server with the DNS admin tools installed against Server 2008 R2 DNS servers. Current AD functional level Windows Server 2003. All DC are DNS server and GC's.

What I have tried:

The followingworks to return all the Name Server records in a zone:

.csv file format

zoneName,hostname,RecordType
1.112.170.in-addr.arpa,nameserver1.contoso.com.,Ns
1.112.170.in-addr.arpa,nameserver2.contoso.com.,Ns
1.112.170.in-addr.arpa,nameserver3.contoso.com.,Ns
2.112.170.in-addr.arpa,nameserver1.contoso.com.,Ns
2.112.170.in-addr.arpa,nameserver2.contoso.com.,Ns
2.112.170.in-addr.arpa,nameserver3.contoso.com.,Ns

Script\Command:

Import-Module DnsServer

$PDCE = Get-ADDomainController -Discover -Service PrimaryDC

import-csv c:\temp\OldNSrecords-test.csv | foreach {

Get-DnsServerResourceRecord -ZoneName $_.zoneName -RRType "Ns" -computerName $PDCE -Node

}

OutPut to screen:

HostName RecordType Timestamp TimeToLive RecordData
-------- ---------- --------- ---------- ----------
@ NS 0 1:00:00 Nameserver1.contoso.com
@ NS 0 1:00:00 Nameserver2.contoso.com

However, replacing the business line (in green above after foreach) with the remove command (in red below)does not work to delete the specific record listed in the .csv, even though it follows thepattern from MS TechNet:

Remove-DnsServerResourceRecord -ZoneName $_.zoneName -RRType "Ns" -name $_.hostname -computerName $PDCE

Error:

PS C:\Windows\system32> C:\Temp\OldNSCleanup.ps1
Remove-DnsServerResourceRecord : Failed to get nameserver1.contoso.com. record in
1.112.170.in-addr.arpa zone on PDCE server.
At C:\Temp\OldNSCleanup.ps1:4 char:1
+ Remove-DnsServerResourceRecord -ZoneName $_.zoneName -RRType "Ns" -name $_.name ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (PDCE:root/Microsoft/...rResourceRecord) [Remove-
DnsServerResourceRecord], CimException
+ FullyQualifiedErrorId : WIN32 9714,Remove-DnsServerResourceRecord​

When I remove the use of the .csv and put the names of the zone and server in the command, I get the same results. Fail.

It's as if the record does not exist, but I can browse to it in the GUI. I foundthis about Missing Glue records, but it does not seem to apply to reverse lookup NS records. I'm thinking that I need to first load each zone into an assembly and then do the removal,but I'm not sure how to do that in PowerShell. I tried piping the get command for the zone to the remove command, but that did not work or I did not have the correct syntax.

I have attempted to use DNSCMD to do the same and that command appears to work, but then fails to actually remove the record.

Here is an example of that command:

import-csv C:\Temp\OldNSrecords-test.csv | foreach {dnscmd.exe "DNSServer.contoso.com" /Recorddelete $_.ZoneName $_.hostname $_.recordType /f}

Output:

Deleted Ns record(s) at 1.112.170.in-addr.arpa
Command completed successfully. [But not really, the NS record is still there]

I have researched several sites including the suggest one here, but this does not fit my requirement.

http://social.technet.microsoft.com/Forums/scriptcenter/en-US/97070ff2-59e2-4f34-9c39-054048e008af/automatically-delete-removed-dcname-servers-and-automatically-add-new-dcname-servers-in-reverse?forum=winserverDS

http://technet.microsoft.com/en-us/library/jj649872.aspx





Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>