Saturday, November 28, 2015

DNS bulk host A and PTR records creation - PowerShell script

Sometimes we need to create many A and PTR DNS records in a short time. Using DNS Management console is not very convenient and fast method because you need to create each records separately by hand. PowerShell 3.0+ (Windows 8/2012+):

Import-CSV records.csv | %{ Add-DNSServerResourceRecordA -ZoneName corp.contoso.com -Name $_."HostName" -IPv4Address $_."IPAddress" -ComputerName <DNSServerName> -CreatePtr}

where records.csv file content would be like:

HostName,IPAddress
server01,192.168.1.101
server02,192.168.1.102
server03,192.168.1.103
server04,192.168.1.104
server05,192.168.1.105

-ComputerName <DNSServerName> is optional and required if you run script for remote DNS server only.