powershell batch add dns records

In the practice of system operation and maintenance, there are often a large number of needs to add dns records. If manually added, it is very time-consuming and error-prone. Windows powershell supports this very well. I wrote the following scripts referring to some technical documents, which is very convenient to use. For reference:

#author:xiaoping.qiu
#date:20180810

#dns server name
$servername = "dcname"

#domain name
$domain = "domain.com"

#dnscreate.csv
#
#   |computer | ip             |
#   | linuxsrv45 | 192.168.127.45 |

$dns_list = Import-Csv D:\dnscreate.csv

$dns_list | %{
$computer = "$($_.computer).$domain"
$addr = $_.ip -split "\."
$rzone = "$($addr[2]).$($addr[1]).$($addr[0]).in-addr.arpa"
dnscmd $servername /recordadd $domain "$($_.computer)" A "$($_.ip)"
dnscmd $servername /zoneadd $rzone /primary
dnscmd $servername /recordadd $rzone "$($addr[3])" PTR $computer
}

Guess you like

Origin blog.51cto.com/sampsondotqiu/2535064