58083

How to Get The Real RecordData from DnsServerResourceRecord Using Powershell?

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:

Get-DnsServerResourceRecord -ComputerName AD_DNS_SERVER -ZoneName 104.10.in-addr.arpa -RRType Ptr | Where-Object {$_.HostName -like '*.128'}`</pre>

I get output that looks like this:

HostName                  RecordType Timestamp            TimeToLive      RecordData                                        
--------                  ---------- ---------            ----------      ----------                                        
104.128                   PTR        10/19/2015 3:00:0... 00:15:00        adl5c260a86ba79.XYZ.net.                          
11.128                    PTR        12/29/2015 6:00:0... 00:15:00        adl3c970e8d7166.XYZ.net.                          
110.128                   PTR        1/29/2012 11:00:0... 00:15:00        nroxitow7tst.ABC.com.                       
114.128                   PTR        1/20/2012 7:00:00 AM 00:15:00        adl5c260a86c29e.ABC.com
</pre>

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:

Get-DnsServerResourceRecord -ComputerName AD_DNS_SERVER  -ZoneName 104.10.in-addr.arpa -RRType Ptr | Where-Object {$_.HostName -like '*.128'} | select HostName, RecordData</pre>

But the output looks like this:

HostName RecordData                
-------- ----------               
104.128  DnsServerResourceRecordPtr
11.128   DnsServerResourceRecordPtr
110.128  DnsServerResourceRecordPtr
114.128  DnsServerResourceRecordPtr
</pre>

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?

Answer1:

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

... |Select-Object HostName, @{Name='RecordData';Expression={$_.RecordData.PtrDomainName}}

Recommend

  • Why am I unable to receive push Notification on Android by ionic framework
  • OpenWrt LibUbi implementation
  • local memory address is valid after function return? [duplicate]
  • Difference between extern and volatile
  • Right way to use __attribute__((NSObject)) with ARC?
  • Smart way to construct class member std::vector
  • precedence of ++ (post,prefix) nd dereference operator
  • How to create instance of a class when the class name is stored in another variable [duplicate]
  • Boost Asio - Message content transmitted wrong
  • Declaring dynamic Multi-Dimensional pointer
  • Error in memset() a 3D array
  • making custom Malloc, what is wrong here?
  • iphone Pass String to another .m file in project
  • How to use INVLPG on x86-64 architecture?
  • How to Get The Real RecordData from DnsServerResourceRecord Using Powershell?
  • Is it safe to combine sizeof and placement new?
  • Menu driven program in c to perform various operations on a linked list
  • Extract point descriptors from small images using OpenCV
  • static_cast - what does conversion between compatible types mean?
  • code behaviour is strange
  • Assembly INT 13h - read disk problem
  • undefined reference to 'cv::CascadeClassifier::detectMultiScale', but other lib linked pro
  • Kahan summation algorithm has big computing error when it is compiled by GCC
  • Pointer on ctypes to use OpenCV on Python 3.1
  • How come C standard library function `strchr` returns pointer to non-const, when given `const char *
  • Sorting an array of pointers
  • Monotouch floating point pointer throws NullReferenceException when not 4-byte aligned
  • Ansible: setting user on dynamic ec2
  • How to obtain service credentials for a service instance created on IBM Bluemix without binding the
  • How to autoplay video in angularjs?
  • Laravel Eloquent integration in Codeigniter
  • Initializing a class using malloc
  • Is it possible to define rest argument in OCaml?
  • java inputstream
  • Numpy divide by zero. Why?
  • AT Commands to Send SMS not working in Windows 8.1
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How do I configure my settings file to work with unit tests?
  • Is it possible to post an object from jquery to bottle.py?
  • Converting MP3 duration time