Powershell script to create reverse lookups (PTR) in Microsoft DNS

We’re switching IP spaces at work and need to create a large amount of reverse lookup PTR records for our PAT/NAT pools.

Microsoft only allows you to manually create one DNS entry at a time via the GUI so I wrote a simple Powershell script that lets you mass create sequential PTR records.

 

####################################
# Windows DNS Server Reverse Lookup Populator
# Created by: Eric Schewe
# Created on: 2014-09-18
####################################
# Summary:
#   Windows DNS doesn't allow for the mass creation of reverse lookup PTR records.
#   This script allows for creating large chunks of reverse lookups based on a
#   incrementing number and pattern.
#
#   In our case we create reverse lookups that follow a certain pattern where
#   ###### is an incrementing number.
#   
#   Example: public#######.site01.mydomain.com
#            |----||-----||------------------|
#            |     |      |
#            |     |      --Defined by $postName
#            |     --Defined by $incrementingName
#            -- Defined by $preName
#
####################################
# Instructions:
#   1. Set $zoneName to the name of the reverse lookup zone you want the DNS
#      created in. Example: "0.0.127.in-addr.arpa"
#   2. Set $startingIP to the first IP you want to create a DNS entry for.
#      Example: "0"
#   3. Set $endingIP to the last IP you want to create a DNS entry for.
#      Example: "126"
#   4. Set $incrementingName to an appropriate starting value if want to use
#      an incrementing number in your naming scheme. If not you can leave this
#      value blank and only $preName and $postName will be used when creating
#      DNS entries
#   5. Set $preName to what ever you'd like the start of the DNS entry to be.
#      This can be left blank.
#   6. Set $postName to what ever you'd like the start of the DNS entry to be.
#      This can be left blank.
#   
####################################

$zoneName="0.0.127.in-addr.arpa"
$startingIP=0
$endingIP=126
$incrementingName=0
$preName="public"
$postName=".site01.mydomain.com"

while ($startingIP -le $endingIP) {
    
    $significanDigit="{0:D4}" -f $incrementingName

    Add-DnsServerResourceRecordPtr -Name "$startingIP" -ZoneName "$zoneName" -PtrDomainName "$preName$significanDigit$postName"

    $startingIP++
    $incrementingName++

}