Link to home
Start Free TrialLog in
Avatar of Michael Leonard
Michael LeonardFlag for United States of America

asked on

need assistance with a powershell script to delete PTR records

can someone assist with the following script, this works well for CNAME or A record deletions but I am trying to modify to delete the PTR [reverse records]

here is the script:
import-csv records.csv | foreach {dnscmd.exe dc1.mydomain.com /Recorddelete $_.ZoneName $_.name $_.recordType /f}

Open in new window


when I setup my input CSV and for the "recordType" column, I put in PTR, it doesn't delete the records on the input CSV file.

thx in advance,
S.
Avatar of Raheman M. Abdul
Raheman M. Abdul
Flag of United Kingdom of Great Britain and Northern Ireland image

can you post the .csv file sample contents please.
Avatar of Michael Leonard

ASKER

sure its 3 columns:

ZoneName,                name,                 recordType
mydomain.com        192.168.20.x        PTR
mydomain.com        192.168.21.x        PTR
...etc
have you tried deleting one of the record by physically running dnscmd.exe cmd with the values of one record in .csv

check any errors you receive.
This may help you: http://www.jetmore.org/john/blog/2012/09/deleting-ptr-records-containing-upper-case-characters-in-microsoft-dns/
What is there in your csv?

To delete 192.168.116.150 you need the following in csv

ZoneName,name,recordType
116.168.192.in-addr.arpa,150,PTR

Open in new window


Commad

Dnscmd /RecordDelete 116.168.192.in-addr.arpa 150 PTR /f
hi Subsun, when I setup my input CSV like you suggested I get the error:
command failed: DNS_ERROR_ZONE_DOES_NOT_EXIST
when I run the script against it:

import-csv records.csv | foreach {dnscmd.exe dc1.mydomain.com /Recorddelete $_.ZoneName $_.name $_.recordType /f}

Open in new window

Try using IP address of the server instead of dc1.mydomain.com as in:


import-csv records.csv | foreach {dnscmd.exe IP_ADDRESS_HERE /Recorddelete $_.ZoneName $_.name $_.recordType /f}
same error: DNS_ERROR_ZONE_DOES_NOT_EXIST
add dot at the end of 116.168.192.in-addr.arpa  in csv file and see
ie
116.168.192.in-addr.arpa.
same error again: DNS_ERROR_ZONE_DOES_NOT_EXIST

Subsun? any ideas?

thx
Check the correct zone name from your DNS server.. the zone name can be 192.in-addr.arpa or 168.192.in-addr.arpa or 116.168.192.in-addr.arpa depends on your DNS configuration..

dnscmd /EnumZones
Hi Subsun, in this case the zone is: 168.192.in-addr.arpa

how should I adjust the input CSV to accommodate this?

thx
Simply changing ZoneName in csv to 168.192.in-addr.arpa should do it..
hi Subsun, yes I did try that while I was waiting for you reply, however I couldn't get it to work.
q: what would the "name" field contain if we make the zonename change to this?

thx - S.
For what it's worth I have confirmed that your code posted in http:#a39494510 does work with the .CSV format Subsun posted.  Tested on a 2008R2 DC/DNS.  The name field just contains the last octet of the IP you want deleted.
hi footech, the zone is setup as: 168.192.in-addr.arpa .. if I only add the last octet of the IP, how would it know what IP to delete. since we would be missing the 3rd octet?
For 192.168.116.150 try 150.116 or 116.150

If not working then run

Dnscmd /ZonePrint 168.192.in-addr.arpa

and check the name format of PTR record.. Sorry I don't have access to any server now..
SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Subsun / Footech,

I have my input file configured exactly as you recommend, and I did run the dnscmd to verify the PTR records.

when I run the script, the message is: Deleted PTR records at 168.192.in-addr.arpa
command completed successfully.

yet, when I look at the zone the records are still there, not purged.

sorry I'm at a bit of a loss.

thx - S.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Assuming you were looking with the DNS Management console - did you refresh your view of the zone?
thx Subsun / Footech. This appears to be a permissions issue on my prod. side. I verified in my lab and you are right, it works fine.

Best,

S.