Quantcast
Channel: DNS – PowerShell for Windows Admins
Viewing all articles
Browse latest Browse all 24

Creating DNS records

$
0
0

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 {
[CmdletBinding()]
param (
[string]$name,
[string]$ipaddress,
[string]$zone = ‘Manticore.org’
)

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

$octs = $ipaddress -split ‘\.’

$revname = “$($octs[3])”
$revzone = “$($octs[2..0] -join ‘.’).in-addr.arpa”
$fqdn = “$name.$zone”

Add-DnsServerResourceRecordPtr -Name $revname -ZoneName $revzone -AllowUpdateAny -PtrDomainName $fqdn

}


Viewing all articles
Browse latest Browse all 24

Trending Articles