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 the DNS 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 Script OneLiner:
Import-CSV -Path "c:\DNSEntries.csv" | ForEach-Object { dnscmd.exe $_.dnsserver /RecordAdd $_.zone $_.name /createPTR $_.type $_.IP }
The output should look like this
Worked great!! had to add 600 entries and was able to do it in no-time. Thanks for posting this!!!
ReplyDeleteThanks for your comment :-)
DeleteTried this and it created the forward lookup DNS entries great, unfortunately no PTR records were created because I dont see reverse lookup entries
ReplyDeleteHey Michael,
DeleteIt is working great for me for both A and PTR, Are you trying to create another type of entry ? not sure it is supported with other type.
Actually Francois, its two things. I didnt modify the script other than the filename source and the CSV format is used as you have shown it. The first thing is the type came out as a Alias(CNAME) and I needed a Host(A). Not sure if I need to modify the dnscmd command to accomodate that change. As far as the PTR I thought that when you do it through the GUI and check of PTR, a record is created in the reverse lookup zone for that subnet.
DeleteBy the way, your script is great because it's so clean. Some of the other ones I have seen are very complicated and I appreciate your approach.
EDIT: I see my error, the type I had in the CSV was C and not A.
DeleteCool! Thanks to let me know Michael.
DeleteI should add this to the post, might be helpful to other people.
Thanks again