Bulk creating DNS records

Recently I needed to create tens of DNS records. This little script automates the creation of DNS records.

The scripts reads a csv file which contains the hostname and the according IP address. This information is used to launch dnscmd which creates the DNS records in the supplied DNS zone.


$DnsServer = "localhost"  
$DnsZone = "test.demo"

\# Load IP configuration csv file  
$HostIPinfo = Import-Csv -Path "C:\\Scripts\\HostIPinfo.csv"

.
\# Create DNS record for every hosts  
$HostIPinfo | ForEach-Object {  
    dnscmd $DnsServer /RecordAdd $DnsZone $_.Server /CreatePTR A $_.Management  
}  

Csv file content

Server,Management  
server01,192.168.0.1  
server02,192.168.0.2  
server03,192.168.0.3  
server04,192.168.0.4  

Share this post:

Social