Create a bunch of DNS Entries using PowerShell and DNScmd.exe

2012/11/01 | less than 1 minute read |

Today I needed to create approx. ~50 DNS A entries. Each of those also need to have a PTR entry.

Lazy as i am… a quick search for PowerShell DNS module did return some interesting things but none who can create both A and< PTR DNS entries at the same time.

So I decided to finally use DNSCMD.exe (full syntax on technet) with powershell.

Requirement: DNSCmd.exe is part of theDNS Server Tools and need to be installed prior to use it. On Windows server you can install it using Add-WindowsFeature RSAT-ADDS-Tools

Here is a quick syntax overview of the Dnscmd.exe that we will be using.

dnscmd.exe <DNSServer> /RecordAdd <DNSZone> <NewEntryName> /CreatePTR A <IPAddress>

First Step: Create a CSV with all the information (in Excel or via PowerShell) here is an example, save it as DNSEntries.csv (in my case at the root of the C: drive)

Second Step: The PowerShell one-liner:

Import-CSV -Path "c:\DNSEntries.csv" |
ForEach-Object {
  dnscmd.exe $_.dnsserver /RecordAdd $ $ /createPTR $_.type $_.IP

And the output should look like the following:

Leave a comment