Michael Leonard
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:
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.
here is the script:
import-csv records.csv | foreach {dnscmd.exe dc1.mydomain.com /Recorddelete $_.ZoneName $_.name $_.recordType /f}
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.
can you post the .csv file sample contents please.
ASKER
sure its 3 columns:
ZoneName, name, recordType
mydomain.com 192.168.20.x PTR
mydomain.com 192.168.21.x PTR
...etc
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/
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
Commad
Dnscmd /RecordDelete 116.168.192.in-addr.arpa 150 PTR /f
To delete 192.168.116.150 you need the following in csv
ZoneName,name,recordType
116.168.192.in-addr.arpa,150,PTR
Commad
Dnscmd /RecordDelete 116.168.192.in-addr.arpa 150 PTR /f
ASKER
hi Subsun, when I setup my input CSV like you suggested I get the error:
command failed: DNS_ERROR_ZONE_DOES_NOT_EX IST
when I run the script against it:
command failed: DNS_ERROR_ZONE_DOES_NOT_EX
when I run the script against it:
import-csv records.csv | foreach {dnscmd.exe dc1.mydomain.com /Recorddelete $_.ZoneName $_.name $_.recordType /f}
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}
import-csv records.csv | foreach {dnscmd.exe IP_ADDRESS_HERE /Recorddelete $_.ZoneName $_.name $_.recordType /f}
ASKER
same error: DNS_ERROR_ZONE_DOES_NOT_EX IST
add dot at the end of 116.168.192.in-addr.arpa in csv file and see
ie
116.168.192.in-addr.arpa.
ie
116.168.192.in-addr.arpa.
ASKER
same error again: DNS_ERROR_ZONE_DOES_NOT_EX IST
Subsun? any ideas?
thx
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
dnscmd /EnumZones
ASKER
Hi Subsun, in this case the zone is: 168.192.in-addr.arpa
how should I adjust the input CSV to accommodate this?
thx
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..
ASKER
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.
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.
ASKER
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..
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Assuming you were looking with the DNS Management console - did you refresh your view of the zone?
ASKER
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.
Best,
S.