Bulk add or replace DNS entries in a zone

There are occasions where we need to do bulk DNS record management such as create and update a large series of records for IP network changes or BCP testing. The environment I am working with is a Microsoft DNS zone. It can be a standard Primary, or an Active Directory Integrated zone. Either type will work with the process we are creating here.

This is not a typical and common process as DNS is often self-managing and dynamic. Let’s assume that you have a number of records from devices that cannot dynamically update, and you are currently using static A and CNAME records to define them.

By using PowerShell to parse a file and craft the command line to use the Microsoft DNSCMD command line tool to get the job done.

This process assumes that your records are all located in the root if the zone you define with the $DNSZone variable. The idea is that you can take this concept and flavor to taste for your particular needs.

To update the zone, we have to use a CSV file which is located in the same directory as the script, or you can define the full drive letter and path with the $InputFile variable if you so desire. The CSV file requires a header row which is name,type,address to give us our attributes for each object when we parse the file.


The script logic is fairly simple:

  1. Define our zone info (server and zone name)
  2. Import the CSV file into an array
  3. Loop through the array
  4. Create a delete command line and use the Invoke-Expression CmdLet to execute it
  5. Create an add command line and use the Invoke-Expression CmdLet to execute it
Please use at your own risk. I have commented out commands that delete any previous DNS entries.

This should add the entries from the text file and add them to your DNS zone. Hope this helps!