Skip to content

Instantly share code, notes, and snippets.

@scorbisiero
Forked from msoler8785/Create-PtrRecords.ps1
Created June 16, 2020 11:06
Show Gist options
  • Save scorbisiero/70ded55101550dff946128ec25a32099 to your computer and use it in GitHub Desktop.
Save scorbisiero/70ded55101550dff946128ec25a32099 to your computer and use it in GitHub Desktop.
Quick PowerShell script to automate PTR Record creation for existing forward lookup zones.
# Creates PTR Records for all A Records in the specified -ZoneName.
# Uses a Class A Subnet for the reverse zone.
$computerName = 'dns-server01';
# Get all the DNS A Records.
$records = Get-DnsServerResourceRecord -ZoneName 'zone.example.com' -RRType A -ComputerName $computerName;
foreach ($record in $records)
{
# The reverse lookup domain name. This is the PTR Response.
$ptrDomain = $record.HostName + '.zone.example.com';
# Reverse the IP Address for the name record.
$name = ($record.RecordData.IPv4Address.ToString() -replace '^(\d+)\.(\d+)\.(\d+).(\d+)$','$4.$3.$2');
# Add the new PTR record.
Add-DnsServerResourceRecordPtr -Name $name -ZoneName '10.in-addr.arpa' -ComputerName $computerName -PtrDomainName $ptrDomain;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment