search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Windows Powershell, Windows Server | No Comment | 6,310 views | 16/03/2014 08:38

You can use following script to verify your PTR records.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Get Reverse Lookup Zones
$ReverseLookupZones = Get-DnsServerZone | Where IsReverseLookupZone -eq $True | Where IsAutoCreated -eq $False
 
foreach ($ReverseLookupZone in $ReverseLookupZones)
{
	# Clear Variables
	$Servers = $Null;
 
	# Get Zone Information
	$DNSZoneName = $ReverseLookupZone.ZoneName
 
	# Get IP Information
	$ReverseIP = $ReverseLookupZone.ZoneName.TrimEnd(".in-addr.arpa");
	$ReverseIPSuffix = $ReverseIP.Split(".")
	[array]::reverse($ReverseIPSuffix)
	$ReverseIPSuffix = $ReverseIPSuffix -join "."
 
	# Get Servers
	$Servers = Get-DnsServerResourceRecord -ZoneName $DNSZoneName | Where HostName -ne "@"
 
	foreach ($Server in $Servers)
	{		
		# Get Server IP Address
		$ServerHostName = $Server.HostName
		$ServerIPSuffix = $ServerHostName.Split(".")
		[array]::reverse($ServerIPSuffix)
		$ServerIPSuffix = $ServerIPSuffix -join "."
		$ServerIPAddress = $ReverseIPSuffix + "." + $ServerIPSuffix
 
		# Get Server DNS Hostname
		$ServerDNSName = $Server.RecordData.PtrDomainName
		$ServerDNSName = $ServerDNSName.TrimEnd(".")
 
		Write-Host Working on $ServerDNSName ..
 
		# Get Server DNS Subnet
		$ServerDNSSubnet = $ServerIPAddress.Split(".")[0] + "." + $ServerIPAddress.Split(".")[1] + "." + $ServerIPAddress.Split(".")[2] + ".0/24"
 
		# Resolve DNS Name
		$DNSName = (Resolve-DnsName $ServerDNSName)
 
		if ($DNSName)
		{
			# Clear Values
			$Control = 0;
 
			foreach ($DNSRecord in $DNSName)
			{
				# Get Reverse DNS Name
				$DNSIPAddress = $DNSRecord.IPAddress
 
				if ($DNSIPAddress -eq $ServerIPAddress)
				{
					$Control = 1;
				}
			}
 
			if ($Control -eq "0")
			{						
				$Output = $ServerIPAddress + ";" + $ServerDNSSubnet + ";" + $ServerDNSName + ";" + $DNSIPAddress
				Add-Content -Value $Output -Path PTRError.txt
				Write-Warning $Output
			}
		}
	}
}

You should run this script on your Windows Server 2012/R2 DNS server with elevated privileges.