Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-05-21
21
Medium Priority
?
1,783 Views
Last Modified: 2013-05-22
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.
0
Comment
Question by:siber1
  • 10
  • 7
  • 4
21 Comments
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39185739
Try
import-csv records.csv | foreach {Remove-DnsServerResourceRecord -zoneName $_.ZoneName -name $_.name -computerName [your DNS Server] -RRType $_.recordType}

Open in new window

0
 

Author Comment

by:siber1
ID: 39185836
thx bepsoccer1..  what should the input csv look like? what columns do i need?
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39185847
I would have a column for ZoneName, Name(this is the record name), and recordType(i.e. A or PTR)
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 

Author Comment

by:siber1
ID: 39185864
bepsoccer, we are not running windows server 2012.. that command doesnt seem to work in win2008?
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39185881
try using remove-DnsObject using this module then http://dnsshell.codeplex.com/releases/view/68243
0
 

Author Comment

by:siber1
ID: 39185934
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
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39185962
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
 

Author Comment

by:siber1
ID: 39186019
cant seem to get it to work. does anyone else have a way to do this via native dnscmd.exe?
0
 
LVL 4

Accepted Solution

by:
bepsoccer1 earned 1000 total points
ID: 39186036
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
 
LVL 40

Assisted Solution

by:Subsun
Subsun earned 1000 total points
ID: 39186141
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
 

Author Comment

by:siber1
ID: 39186174
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39186184
Try by replacing Get-DnsRecord
with
Get-DnsRecord -Zone Test.com -Server Server
0
 

Author Comment

by:siber1
ID: 39186199
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
 
LVL 40

Expert Comment

by:Subsun
ID: 39186203
Get-DnsRecord : Access is denied .. looks like a permission issue..
0
 

Author Comment

by:siber1
ID: 39186209
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
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39186211
Have you tried the dnscmd I mentioned above?
0
 

Author Comment

by:siber1
ID: 39186219
hi bepsoccer, i did try that and it ran, but none of the records were deleted.
0
 

Author Comment

by:siber1
ID: 39186229
bep..  maybe my input file is incorrect? for recordType i have A
is that correct?
0
 
LVL 4

Expert Comment

by:bepsoccer1
ID: 39186238
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
 

Author Closing Comment

by:siber1
ID: 39186262
thanks guys, both to work with a bit of an adjustment. really appreciate it!
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39189411
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question