Like this: Get-DnsServerResourceRecord -ZoneName "reverse-lookup-zone-name"
retrieve DNS records help
Hi all,
We have many reverse lookup zones in our AD integrated zone of our domain mydomain.local.
How to retrieve all PTR records for each reverse lookup zones through script?
Unfortunately I don't have much knowledge of how to create Powershell script, so I hope someone has an example
for me similar to this that I can reuse.
Thank you!
Windows Server PowerShell
3 answers
Sort by: Most helpful
-
Rich Matheisen 47,886 Reputation points
2022-05-26T18:15:10.97+00:00 -
Rich Matheisen 47,886 Reputation points
2022-05-28T14:54:29.73+00:00 When dealing with PTR records, the HOST is that part of the IP address that uniquely identifies the PTR record within the zone. The name in the PTR record (while it's usually a DNS name) doesn't necessarily refer to an A (or any other type of DNS record). There's nothin in DNS that states, for instance, that an A or AAAA record has to have an associated PTR record, or that a PTR record has to represent the DNS name of any other record in your (or any) DNS servers forward lookup zones.
Given that, this will attempt to find a PTR record given the data in the CSV:
# CSV has these columns: Host, ZoneName, Data Import-CSV YOUR-CSV-NAME-GOES-HERE | ForEach-Object{ Get-DNSServerResourceRecord -ComputerName YOUR-DNS-SERVER-NAME -name $_.Host -zonename $_.ZoneName -RRType PTR }
Note that there's no error handling, and that I have no idea what you want to do with the information in the PTR if one is found.
-
Rich Matheisen 47,886 Reputation points
2022-06-10T02:37:52.323+00:00 Give this a try -- NOTE: it must be "Run as administrator". Also, it works only with AD-integrated DNS zones:
$Zone = "1.168.192.in-addr.arpa" $DnsServer = (Get-ADDomain).ReplicaDirectoryServers[0] $DnsRecordQueryParams = @{ 'Computername' = $DnsServer 'Class' = 'MicrosoftDNS_PTRType' 'Namespace' = 'root\MicrosoftDNS' 'Filter' = "ContainerName = '$Zone' AND OwnerName <> '$Zone'" # AND Timestamp <> 0 <=== add this if you want only dynamic records } Get-WmiObject @DnsRecordQueryParams | ForEach-Object { $parts = $_.Textrepresentation -split " " $reverse = $parts[0] -replace '\.in-addr\.arpa', "" $ipparts = $reverse -split "\." # IPv4 ONLY!!!!! $ip = $ipparts[(($ipparts.count - 1)..0)] [PSCustomObject]@{ 'DnsServerName' = $DnsServer 'Zone' = $_.DomainName 'Host' = $ipparts[0] 'Name' = $_.RecordData 'Type' = if ($_.timestamp -gt 0) { 'Dynamic' } else { 'Static' } 'IP' = ($ip -join ".") } }