Created
March 26, 2020 19:09
-
-
Save rukas/ac9034c73a9c0849bdd5bd4f48ab4239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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