DNS A Record deletion in bulk via csv

I have all of Manning Powershell books but only two of them discuss DNSServerResourceRecord deletions yet, even those are one-off deletions.

What if I have 200 A records I want to delete?

I can put the following in a csv:

Host Zone IP Address
 

and I have this script from AD Management in MOL:

[pre]

$zone=‘myZone’
$dnsserver=‘myDNSServer’

Remove-DnsServerResourceRecord -ZoneName $zone -Name $dnsserver -RRType A[/pre]

…but how can I create a forEach loop to iterate across all the host records I want to remove?

 

It’s not enough to have them … you have to read them as well. :wink: :smiley:

You might start with learning the very basics of Powershell.

Import-Csv -Path ‘Path to your CSV file’ |
ForEach-Object {
Remove-DnsServerResourceRecord -ZoneName $.Zone -Name $.Host -RRType A # -Force
}

If you’re really sure you can remove the # to delete all the records without confirmation

@jeff-taylor, related: https://powershell.org/forums/topic/use-ps-instead-of-dnscmd-for-bulk-dnsserver-changes-via-csv/

thanks kvprasoon. (I thought my first post didn’t go through)

[quote quote=156092]It’s not enough to have them … you have to read them as well.
[/quote]

Yes, I certainly read through all but only saw 2 DNSServer related topics and that was only for a single record. I’ll try your tips.

Too bad the csv doesn’t have zonename, name, and rtype. You could pipe it in directly:

import-csv file.csv | Remove-DnsServerResourceRecord -whatif