Link to home
Start Free TrialLog in
Avatar of Michael Leonard
Michael LeonardFlag for United States of America

asked on

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.
Avatar of bepsoccer1
bepsoccer1
Flag of United States of America image

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

Open in new window

Avatar of Michael Leonard

ASKER

thx bepsoccer1..  what should the input csv look like? what columns do i need?
I would have a column for ZoneName, Name(this is the record name), and recordType(i.e. A or PTR)
bepsoccer, we are not running windows server 2012.. that command doesnt seem to work in win2008?
try using remove-DnsObject using this module then http://dnsshell.codeplex.com/releases/view/68243
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

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.
cant seem to get it to work. does anyone else have a way to do this via native dnscmd.exe?
ASKER CERTIFIED SOLUTION
Avatar of bepsoccer1
bepsoccer1
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Try by replacing Get-DnsRecord
with
Get-DnsRecord -Zone Test.com -Server Server
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
Get-DnsRecord : Access is denied .. looks like a permission issue..
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?
Have you tried the dnscmd I mentioned above?
hi bepsoccer, i did try that and it ran, but none of the records were deleted.
bep..  maybe my input file is incorrect? for recordType i have A
is that correct?
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.
thanks guys, both to work with a bit of an adjustment. really appreciate it!
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/