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
1,691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

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 250 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 250 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

732 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