Monday, October 19, 2015

Adding Multiple Resource Records in a Microsoft Based DNS Server

It happens sometimes that you have to add multiple Host records in a Windows Server 2012 R2 based DNS server. Using Power Shell script can do the magic.
There are 3 main Phases,

      A-   Preparing DNS Server

In order to run DNS related commands we need “DNSShell” module to be extracted to DNS server. This module is not available by default and can be downloaded from this URL;


-          Download and extract the “DNSShell” module in following location (considering C: is the home directory on your server)
C:\Windows\System32\WindowsPowerShell\v1.0\Modules

      B-   Preparing the CSV File containing desired entries

-          You need at least two parameters
1-      Host Name
2-      IP Address



The entries should look like as shown in the screen shot



-          Save this file as .CSV, in this example I have used “newhosts.CSV” as file name.

 C- Execution of Script


-          Create a new Folder at this location
C:\DNS-Temp

-          Place the csv file in the folder “DNS-Temp”
Following script will be used to perform this job (I have done modifications in the script to fit in my example. These modifications can be seen as bold and italic)

Import-Module DNSShell
Import-CSV c:\DNS\newHosts.csv | %{
New-DNSRecord -Name $_."HostName" -RecordType A -ZoneName relic.org -IPAddress $_."IPAddr"
}  

-          The Power Shell the script must run without any error messages.




-          A comparison of Forward lookup zone before and after running the script can be seen in figures below.

Before:




           After:















No comments:

Post a Comment