Creating DNS records

Following on from my previous post about creating a reverse lookup zone in DNS here’s a function to create records in that zone.

The function takes an IP address and name (of host) and uses Add-DnsServerResourceRecordA  to add the record to the forward lookup zone – I use my default AD zone.

The function then splits the IP address. Uses the last octet for the name in the reverse record. Creates the reverse lookup zone from the first 3 octets – notice how the range parameter is used in a decreasing way to specify the order of the octets – to create the reverse lookup zone. The host name and zone are used to create the FQDN of the host.

Add-DnsServerResourceRecordPtr  is used to create the reverse (PTR) record.

function new-dnsrecord {
  param (
    [string]$zone = ‘’

  Add-DnsServerResourceRecordA -Name $name -ZoneName $zone -AllowUpdateAny -IPv4Address $ipaddress

  $octs = $ipaddress -split ‘\.’

  $revname = “$($octs[3])”
  $revzone = “$($octs[2..0] -join ‘.’)”
  $fqdn = “$name.$zone”
  Add-DnsServerResourceRecordPtr -Name $revname -ZoneName $revzone -AllowUpdateAny -PtrDomainName $fqdn


This entry was posted in DNS, Powershell, Windows Server 2012 R2. Bookmark the permalink.

One Response to Creating DNS records

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s