need a powershell or quest AD cmdlets script to delete a list of DNS records from an input file

can someone provide a script that i can run to delete a set of DNS records [in an input .csv file] from our internal DNS zone. [ADI]

would like to remove the host A and associated PTR records for each in the .csv file

thx in advance.

S.
siber1Asked:
Who is Participating?
 
bepsoccer1Connect With a Mentor Commented:
import-csv records.csv | foreach {dnscmd.exe <DNS Server> /Recorddelete $_.ZoneName $_.name(should be FQDN) $_.recordType /f}

Open in new window


http://technet.microsoft.com/en-us/library/cc759561(v=ws.10).aspx
0
 
bepsoccer1Commented:
Try
import-csv records.csv | foreach {Remove-DnsServerResourceRecord -zoneName $_.ZoneName -name $_.name -computerName [your DNS Server] -RRType $_.recordType}

Open in new window

0
 
siber1Author Commented:
thx bepsoccer1..  what should the input csv look like? what columns do i need?
0
NEW Internet Security Report Now Available!

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out this quarters report on the threats that shook the industry in Q4 2017.

 
bepsoccer1Commented:
I would have a column for ZoneName, Name(this is the record name), and recordType(i.e. A or PTR)
0
 
siber1Author Commented:
bepsoccer, we are not running windows server 2012.. that command doesnt seem to work in win2008?
0
 
bepsoccer1Commented:
try using remove-DnsObject using this module then http://dnsshell.codeplex.com/releases/view/68243
0
 
siber1Author Commented:
so just to clarify, is this the exact syntax i should be using:

import-csv records.csv | foreach {remove-DnsObject -zoneName $_.ZoneName -name $_.name -computerName [your DNS Server] -RRType $_.recordType}

Open in new window

0
 
bepsoccer1Commented:
I have powershell 3 which it is not supported on so I can't install it on my current machine.  Try get-help remove-DnsObject to see if the switches are different.  -zoneName may be -zone with this module.
0
 
siber1Author Commented:
cant seem to get it to work. does anyone else have a way to do this via native dnscmd.exe?
0
 
SubsunConnect With a Mentor Commented:
You may try this, (I have not tested.. :-) ...So test it before you run it in production)

Import-Module DNSShell
Import-Csv C:\DNS.csv | % {
#Find A Record
$Server = $_.Server
$IP = $_.IP
$Record = Get-DnsRecord | ?{$_.RecordType -eq "A" -and $_.Name -eq $Server -and $_.RecordData -eq $IP}
IF ($Record) {
#Remove A Record
$Record | remove-DnsObject -Force
	
	# Find PTR
	$PTR = Get-DnsRecord | ?{$_.RecordType -eq "PTR" -and $_.RecordData -eq $IP}
	If ($PTR){
	#Remove PTR
	$PTR | remove-DnsObject -Force
    }
  }
}

Open in new window


CSV Format..
Server,ip
ServerA.test.com,172.10.10.10
ServerB.test.com,172.10.10.11

Open in new window

0
 
siber1Author Commented:
Hi Subsun, thanks for the script. i just ran it and here is the error:

Get-DnsRecord : Invalid namespace
At C:\Users\siber1\Desktop\run.ps1:6 char:24
+ $Record = Get-DnsRecord <<<<  | ?{$_.RecordType -eq "A" -and $_.Name -eq $Server -and $_.RecordData -eq $IP}
    + CategoryInfo          : InvalidOperation: (DnsShell.PowerS...anagementCmdlet:RuntimeType) [Get-DnsRecord], Manag
   ementException
    + FullyQualifiedErrorId : WMIManagementException,DnsShell.PowerShell.CmdLet.DnsRecord
0
 
SubsunCommented:
Try by replacing Get-DnsRecord
with
Get-DnsRecord -Zone Test.com -Server Server
0
 
siber1Author Commented:
Hi Subsun, now getting this error:   [i may have to install the quest tools directly on the dns server]?

Get-DnsRecord : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At C:\Users\siber1\Desktop\run.ps1:6 char:24
+ $Record = Get-DnsRecord <<<<  -Zone mydomain.com -Server myserver.domain.com | ?{$_.RecordType -eq "A" -and $_.Name -eq
$Server -and $_.RecordData -eq $IP}
    + CategoryInfo          : PermissionDenied: (DnsShell.PowerS...anagementCmdlet:RuntimeType) [Get-DnsRecord], Unaut
   horizedAccessException
    + FullyQualifiedErrorId : UnauthorizedAccessException,DnsShell.PowerShell.CmdLet.DnsRecord
0
 
SubsunCommented:
Get-DnsRecord : Access is denied .. looks like a permission issue..
0
 
siber1Author Commented:
sorry to be a pain Subsun, when i try to run this on the server [new install] it doesnt recognize get-dnsrecord.

when i manually run: import=module DNSShell
it cannot load it.

latest version of quest tools? any ideas?
0
 
bepsoccer1Commented:
Have you tried the dnscmd I mentioned above?
0
 
siber1Author Commented:
hi bepsoccer, i did try that and it ran, but none of the records were deleted.
0
 
siber1Author Commented:
bep..  maybe my input file is incorrect? for recordType i have A
is that correct?
0
 
bepsoccer1Commented:
Try just the dnscmd with one of your records without the csv import to see if the syntax deletes the expected record. If it works verify you csv fields match your variables.
0
 
siber1Author Commented:
thanks guys, both to work with a bit of an adjustment. really appreciate it!
0
 
SubsunCommented:
I guess you already figured out, To load DNSShell using Import-Module DNSShell
you need to install the module.. Check this link..
http://dnsshell.codeplex.com/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.