Skip to content

Instantly share code, notes, and snippets.

@rukas
Created March 26, 2020 19:09
Show Gist options
  • Save rukas/ac9034c73a9c0849bdd5bd4f48ab4239 to your computer and use it in GitHub Desktop.
Save rukas/ac9034c73a9c0849bdd5bd4f48ab4239 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
.DESCRIPTION
.PARAMETER csvPath
The absolute path where the CSV files will be placed.
The default location is the current directory(.).
.EXAMPLE
.NOTES
#>
[CmdletBinding()]
PARAM (
[Parameter()]
[String[]]
$dnsServer = '10.10.14.13'
)
$dnsZones = Get-DnsServerZone -ComputerName "$dnsServer" `
| Where-Object {$_.ZoneType -eq "Primary" -and $_.IsReverseLookupZone -eq $false}
Write-Host "DNS Zones Found:"
$dnsZones | Select-Object ZoneName
Foreach ($dnsZone in $dnsZones){
Write-Host "***** Working on DNS Zone:" $dnsZone.ZoneName "*****"
$aRecords = Get-DnsServerResourceRecord -ZoneName $dnsZone.ZoneName -ComputerName `
"$dnsServer" | Where-Object {$_.RecordType -eq "A"}
foreach ($a in $aRecords){
$fqdn = $a.Hostname + "." + $dnsZone.ZoneName
$ip = ($a.RecordData).IPv4Address
try{
$resolvedHostname = [System.Net.Dns]::GetHostEntry($ip).HostName
}
Catch{
$resolvedHostname = " "
}
If($fqdn -ne $resolvedHostname){
Write-Host "$fqdn does not have a matching reverse record...fixing it.."
$first = ($ip.IPAddressToString -split '\.')[3]
$second = ($ip.IPAddressToString -split '\.')[2]
$third = ($ip.IPAddressToString -split '\.')[1]
$fourth = ($ip.IPAddressToString -split '\.')[0]
$reverseIP = "$first.$second.$third.$fourth"
$last3Octets = "$second.$third.$fourth"
Add-DnsServerResourceRecordPtr -ComputerName "$dnsServer" -Name $first `
-ZoneName "$last3Octets.in-addr.arpa" -PtrDomainName $fqdn -WhatIf
}
Else{
Write-Host "$fqdn has a matching reverse record...nothing to do here..."
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment