How Do You Add Multiple DNS A Records in Active Directory Using a File?

Problem scenario
You want to create multiple A records in DNS. But to do it manually using the MMC would take too long. What should you do?

Solution

  1. Open the MMC and browse Active Directory. On the left the name of the A.D. server should be fairly obvious (e.g., contint or foobarsrv).
  2. Open PowerShell as an administrator.
  3. Create a .txt file called arecords.txt with this as the header:

name,ip

  1. Underneath that header place DNS names followed by a comma and a space, and finally the associated IP address. Have one DNS name and IP address pair per line.
  2. Change directories to where you have saved this .txt file.
  3. Run this command, but substitute contint for the name of the DNS server:
Import-Csv .\arecords.txt | foreach{Add-DnsServerResourceRecordCName -Name $_.name -ZoneName test.local -HostNameAlias $_.cname -ComputerName contint}
  1. You are done. It may take a few minutes for the DNS records to appear. This solution above was adapted from this posting.

Leave a comment

Your email address will not be published. Required fields are marked *