Skip to content

Instantly share code, notes, and snippets.

@msoler8785
Last active April 2, 2024 19:25
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save msoler8785/498332c622f93ace02b5d05e47845001 to your computer and use it in GitHub Desktop.
Save msoler8785/498332c622f93ace02b5d05e47845001 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;
}
@msoler8785
Copy link
Author

@mcdonamw just revisiting it today because I need to use the script. I originally created this because I had to rebuild my PTR zones from pre-existing forward records. I didn't see a way to do this in bulk at the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment