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.
siber1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
can you post the .csv file sample contents please.
0
siber1Author Commented:
sure its 3 columns:

ZoneName,                name,                 recordType
mydomain.com        192.168.20.x        PTR
mydomain.com        192.168.21.x        PTR
...etc
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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/
0
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

SubsunCommented:
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
0
siber1Author Commented:
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

0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
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}
0
siber1Author Commented:
same error: DNS_ERROR_ZONE_DOES_NOT_EXIST
0
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
add dot at the end of 116.168.192.in-addr.arpa  in csv file and see
ie
116.168.192.in-addr.arpa.
0
siber1Author Commented:
same error again: DNS_ERROR_ZONE_DOES_NOT_EXIST

Subsun? any ideas?

thx
0
SubsunCommented:
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
0
siber1Author Commented:
Hi Subsun, in this case the zone is: 168.192.in-addr.arpa

how should I adjust the input CSV to accommodate this?

thx
0
SubsunCommented:
Simply changing ZoneName in csv to 168.192.in-addr.arpa should do it..
0
siber1Author Commented:
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.
0
footechCommented:
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.
0
siber1Author Commented:
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?
0
SubsunCommented:
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..
0
footechCommented:
Sorry, I just assumed you had a reverse zone for a /24 subnet.  With a reverse zone like yours it would be the last two octets in reversed order, just as if you were writing out the query for the PTR record.  So a query for the IP 192.168.116.150 would be 150.116.168.192.in-addr.arpa, or 150.116 in the 168.192.in-addr.arpa zone.  Subsun's absolutely right that a zoneprint would show you this info.  Or if you were storing the zone as a file (i.e. not AD Integrated) then you could open it and see the same thing.
0
siber1Author Commented:
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.
0
SubsunCommented:
I just tried with following csv file and it works for me..

for For 192.168.116.150
ZoneName,name,recordType
168.192.in-addr.arpa,150.116,PTR

Open in new window

Dnscmd /RecordDelete 168.192.in-addr.arpa 150.116 PTR /f
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
footechCommented:
Assuming you were looking with the DNS Management console - did you refresh your view of the zone?
0
siber1Author Commented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.