Use PS instead of DNSCMD for Bulk DNSServer changes via csv

I would like to know how to do bulk DNS Server deletes using powershell instead of this dnscmd command:

[pre]dnscmd DNSServerName/RecordDelete HOSTNAME001 A /f

dnscmd DNSServerName/RecordDelete HOSTNAME002 A /f

dnscmd DNSServerName/RecordDelete HOSTNAME003 A /f[/pre]

instead of doing line by line deletions at the command prompt, is there a way to ingest the csv then interate over a foreach and run Remove-DnsServerResourceRecord?

Yes of course you can use CSV and then a Foreach here . You can read the documentation of Import-Csv.

  • Import the csv and save the output to a variable.
  • use Foreach loop to iterate through each item in CSV and pass the relevant values to Remove-DnsServerResourceRecord

I believe this can be done without a foreach as well. something like below. But your CSV headers should match the relevant parameter names of Remove-DnsServerResourceRecord cmdlet. Please read the help doc to identify the parameter names.

Import-Csv -Path c:\temp\ddnsrecords.csv | Remove-DnsServerResourceRecord