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,587 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
Comment Utility
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
Comment Utility
thx bepsoccer1..  what should the input csv look like? what columns do i need?
0
 
LVL 4

Expert Comment

by:bepsoccer1
Comment Utility
I would have a column for ZoneName, Name(this is the record name), and recordType(i.e. A or PTR)
0
 

Author Comment

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

Expert Comment

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

Author Comment

by:siber1
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:siber1
Comment Utility
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
Comment Utility
Try by replacing Get-DnsRecord
with
Get-DnsRecord -Zone Test.com -Server Server
0
 

Author Comment

by:siber1
Comment Utility
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
Comment Utility
Get-DnsRecord : Access is denied .. looks like a permission issue..
0
 

Author Comment

by:siber1
Comment Utility
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
Comment Utility
Have you tried the dnscmd I mentioned above?
0
 

Author Comment

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

Author Comment

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

Expert Comment

by:bepsoccer1
Comment Utility
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
Comment Utility
thanks guys, both to work with a bit of an adjustment. really appreciate it!
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Join & Write a Comment

OfficeMate Freezes on login or does not load after login credentials are input.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now