DNS recorddata

get-dnsserverresourcerecord -computername server -zonename zone.com -RRType A

returns five columns. one of them is “name” and another is “Recorddata.” name contains name, and recorddata contains the ip address.

get-dnsserverresourcerecord -computername server -zonename zone.com -RRType A | -select name,Recorddata

correctly returns the name in the first column, and “DNSServerResourceRecordA” on every row in the second column.

how do I display just the name and ip address?

The default view that gets used when you just run Get-DnsServerResourceRecord does not display actual property names, and does some stuff to create a friendlier display than would otherwise happen by default.

Once you use Select-Object, you dis-engage that default view.

Start by piping the command to Get-Member so you can see the “real” property names. Or, use Select-Object * to see something similar. That’ll help you figure it out. See also, https://powershell.org/kb/commands-default-output-can-lie/.

Part of what can happen sometimes is that a property contains another complex object - like a DNSServerResourceRecordA object. You might need to use Select-Object’s -ExpandProperty parameter to expand just that problematic object so you can see what IT looks like.

thanks Don. I did not know about -expandproperty. get-member isn’t really helpful, but I do see ipv4address when I use -expandproperty recorddata at the end of my original command.

unfortunately I still don’t know how to JUST show hostname and ipv4address in the output.

… | -select hostname -expandproperty recorddata

gets me close, but there’s an extra column called “PSComputername.” the column is empty, but it’s still there. is there a way to select just one of the expanded parts of recorddata?

It can be tricky. What you want is the combined output of two objects. Let’s take these specific ones out of it for a second.

Let’s say I have Object A, and I want Property1, Property2, and Property3. There’s also a Property4, and it’s actually a sub-object, and I want Property4A from it. So that’s four bits of output total.

Get-ObjectA |
Select-Object -Property Property1,Property2,Property3,@{
e={$_.Property4 | Select-Object -ExpandProperty Property4A}

That’s the basic model.

The first Select-Object is getting the “top level” properties from Object A. I’m then creating a “custom property” (also called a “calculated property”). In it, I set the output property name (n=) as Property4A, so that’s what’ll show in the output table. I then create an expression (e=) that defines what the custom property will contain.

$_ represents whatever object Select-Object is working with, and so I take its Property4 - which is a sub-object, remember - and pipe it to another Select-Object, extracting the contents of the sub-object’s Property4A, which is what I want.

The resulting output is a single object with four properties, which PowerShell would by default display as a four-column table.

This solves the “the thing I want to display includes sub-objects, and I only need a portion of the info those sub-objects contain.” In your case, RecordData is Property4A… think you can take it from there?

Get-DnsServerResourceRecord -ComputerName server -zonename zone.com -RRType A | select hostname,@{label=‘IP Address’; expression={$_.recorddata | select -expandproperty ipv4address}} | ft -AutoSize

(after some research to figure out what your ‘e’ stood for :slight_smile: )

thank you again. I’ve actually always wondered how to change the column names anyway, so. two birds, one thread.

well. now. this is great and all for outputting data. but what if I want to query dns, and for records whose ip address is how do I use an expanded property in a where clause?

Ah, that’s what -contains and -in are for.

Assume I have an object $obj, which has a property prop. prop is actually a collection of [string] objects.

… | where { $obj.prop -contains “this” } | …

Because I’m providing a [string] “this”, and that’s what $obj.prop contains, it’ll work.


I must have missed something.

Get-DnsServerResourceRecord -ComputerName DNSServer-ZoneName zone.com | ? {$_.recorddata -contains “10”}

is not returning anything (every dns record in zone.com starts with 10)

So, that’s the trick with -contains, It isn’t a wildcard match. It’s looking to see if $_.recorddata contains EXACTLY “10.” Which, of course, it doesn’t, right?

So there’s no way to do a wildcard match across a collection. You’ll probably have to use a ForEach instead, and enumerate all the RecordData properties individually.

my end goal is to feed a list of IPs into a foreach statement, and have the script output a list of FQDNs from DNS. but at this point i’m just testing with one IP that I know has a dns record.

so if I do this:
Get-DnsServerResourceRecord -ComputerName DNSServer -ZoneName zone.com -rrtype a | ? hostname -like host1 |select hostname, @{label=‘IP Address’;expression={$_.recorddata |select -expandproperty ipv4address}}

the output is hostname ‘host1’ and ip address so obviously there is an A record in my DNS named host1 with that ip address.

but if I try to reverse the process to return ‘host1’ from the ip address, nothing is returned from the following:

Get-DnsServerResourceRecord -ComputerName DNSServer -ZoneName zone.com -rrtype a | ? {$_.recorddata -contains ‘’}

You need a reverse lookup zone ;).

So, do this:

Get-DnsServerResourceRecord -ComputerName DNSServer -ZoneName zone.com -rrtype a | select -expand recorddata | get-member

What’s the TypeName?

Hey Don, your contribution has been very helpful. My challenge is a bit more complex than John’s. I need to move all of my Zones to a public DNS provicer that would only accept csv file in the format and order below.



Basically the challenge is how to place different possible values in the same column.

I want the column “value” to contain either IPv4Address,Hostnamealias, etc. based on recordtype.


You can do this,
I would suggest to DIY.
Build a CSV and iterate through the records to append the contents into CSV, set the value property based on the RecordType of the incoming object. Give it a try and update here when you get isssues, we are here to help you.

PS: It would be good if you post a new thread based on your attempt.