How to Get The Real RecordData from DnsServerResourceRecord Using Powershell?

Question:

I’m using PowerShell to extract information from an Active Directory DNS server and I’m having trouble getting to the data I want.

Specifically, I’m trying to get the names of hosts that belong to a particular subnet, 10.104.128.x.

When I use the following commands:

I get output that looks like this:

What I really want are the first column, (HostName), which has the last two octets of the IP; and the fifth column, (RecordData), which has the name of the host the IP is assigned to.

The hostname is the data I really want/need. And I see it right there!

So I used the select command to pare down the output in the pipe train. New command looks like this:

But the output looks like this:

Dosen’t get me the hostname though. Just the type of object the RecordData is but not the data that the object contains, perhaps?

I also tried piping the output to CSV and got the same result.

Then I tried looking at the DnsServerResourceRecord object properties with Get-Member. That showed me the object had a property called PSComputerName. I thought maybe that would have the name of the host but that came up blank when I tried to select it.

I then Googled around a bit and found a few pages that recommended a few ways to use RecordData.ipv4address to coax the data out of the DnsServerResourceRecordPtr object but I haven’t gotten any of them to work yet. Output still prints blanks.

So my question is: does a reliable method exist for getting the actual hostname from a PTR record?

Answer:

To select the PtrDomainName property from the DnsServerResourceRecordPtr object, use a calculated property:

Source:

How to Get The Real RecordData from DnsServerResourceRecord Using Powershell? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply