Skip to main content

PowerShell Tips #2 - Working with Multi-Instance or Nested Properties

The objective here is to create reports of objects that contain properties with multiple instances, or nested properties.

Example is Get-DNSServer

Get-DNSServer by itself, with no parameters, produces a very detailed, multiple-heading report with a ton of detail.   The internal code to produce this report will be the subject of another technote.

For this exercise though, see the outout from the command

PS C:\ > Get-DnsServer |gm -MemberType Property

Name                       MemberType Definition
----                       ---------- ----------
PSComputerName             Property   string PSComputerName {get;}
ServerCache                Property   CimInstance#Instance ServerCache {get;set;}
ServerDiagnostics          Property   CimInstance#Instance ServerDiagnostics {get;set;}
ServerDsSetting            Property   CimInstance#Instance ServerDsSetting {get;set;}
ServerEdns                 Property   CimInstance#Instance ServerEdns {get;set;}
ServerForwarder            Property   CimInstance#Instance ServerForwarder {get;set;}
ServerGlobalNameZone       Property   CimInstance#Instance ServerGlobalNameZone {get;set;}
ServerGlobalQueryBlockList Property   CimInstance#Instance ServerGlobalQueryBlockList {get;set;}
ServerRecursion            Property   CimInstance#Instance ServerRecursion {get;set;}
ServerRootHint             Property   CimInstance#InstanceArray ServerRootHint {get;set;}
ServerScavenging           Property   CimInstance#Instance ServerScavenging {get;set;}
ServerSetting              Property   CimInstance#Instance ServerSetting {get;set;}
ServerZone                 Property   CimInstance#InstanceArray ServerZone {get;set;}
ServerZoneAging            Property   CimInstance#InstanceArray ServerZoneAging {get;set;}
ServerZoneScope            Property   CimInstance#InstanceArray ServerZoneScope {get;set;}


What I am interested in reporting is the IP Addresses of the Forwarders, which is contained in the "ServerForwarder" property.


So, we now type "(get-dnsserver).ServerForwarder" and get the following:

UseRootHint        : True
Timeout(s)         : 3
EnableReordering   : True
IPAddress          : {10.1.1.4, 10.2.1.20}
ReorderedIPAddress : {10.1.1.4, 10.2.1.20}


Now type:
PS C:\ > (get-dnsserver).ServerForwarder | GM

Name                      MemberType     Definition
----                      ----------     ----------
EnableReordering          Property       bool EnableReordering {get;set;}
PSComputerName            Property       string PSComputerName {get;}
Timeout                   Property       uint32 Timeout {get;set;}
UseRootHint               Property       bool UseRootHint {get;set;}
IPAddress                 ScriptProperty System.Net.IPAddress[] IPAddress {get=[OutputType([Syste...
ReorderedIPAddress        ScriptProperty System.Net.IPAddress[] ReorderedIPAddress {get=[Outpu...


Notice that a "Property" of the ServerForwarder property is not a Property at all, but rather a ScriptProperty.  It contains multiple values as a sudo-property. 

So lets keep going.   
PS C:\> ((get-dnsserver).ServerForwarder).IPAddress
 

Address            : 67174666
AddressFamily      : InterNetwork
ScopeId            :
IsIPv6Multicast    : False
IsIPv6LinkLocal    : False
IsIPv6SiteLocal    : False
IsIPv6Teredo       : False
IsIPv4MappedToIPv6 : False
IPAddressToString  : 10.1.1.4

Address            : 335610378
AddressFamily      : InterNetwork
ScopeId            :
IsIPv6Multicast    : False
IsIPv6LinkLocal    : False
IsIPv6SiteLocal    : False
IsIPv6Teredo       : False
IsIPv4MappedToIPv6 : False
IPAddressToString  : 10.2.1.20


So how do we query the DNS Server and spit out this magical list of IP Addresses?
Method 1) 
PS C:\ > (((get-dnsserver).ServerForwarder).IPAddress).IPAddressToString
10.1.1.4
10.2.1.20


Method 2)


PS C:\ > Get-DnsServer |%{$_.ServerForwarder | %{($_.IPAddress).IPAddressToString}}

10.1.1.4
10.2.1.20


End of Lesson.

Comments

Popular posts from this blog

"Blinky" TDOA RDF Detector

Our local Amateur Radio club is building a Radio Direction Finding TDOA (Time Difference of Arrival) detector that has LED's to indicate the direction (Left or right) of the fox.  Here are the build instructions.   (Note: this project was originally presented by NZ1J.  See his video:   https://www.youtube.com/watch?v=mNqUKYkifOo&t=68s   ) Here is the completed project: We start with the schematic:   Note that you either install PIN Diode pairs s D3 and D2, or Diodes pair D1 and D4.   The difference between these is the packaging.  If you are ok with Surface mount, then install D1/D4.  If you want discrete components use D3/D2. Next is the PCB.   The PCB can be ordered using the GRBR files available from the author.  The BOM for the electronic parts is as such: Doppler Direction Finder Bill of Materials   11/12/2021        Qty Part Digi-key Part Numbe...

Radio Direction Finding - TDOA

This article describes a few projects that I built from plans for Amateur Radio Fox Hunting. Basically, the hobby/sport is for someone to hide a few low power "Foxes", which are small transmitters that beep or send Morse Code, and then have a bunch of HAM's try to find them. The first project that I built was a Yagi Antenna (Directional receiver) and a 4MHZ Offset Attenuator.  The attenuator is needed when you get close to the fox and you need to reduce the power of the received signal.  I struggled with this setup because, on my first 2 fox hunts, there was too much reflection and multi-path interference.  This causes false direction detection and if you are not mentally prepared for this, you want to throw all of your equipment into a garbage can and take up a different hobby.   There are some truly strange individuals who find this frustration fun and enjoy making other people suffer, but I will leave that discussion for another day.  Anyw...

Wireless device monitoring with wavemon

Wireless device monitoring with wavemon wavemon is a wireless device monitoring software that allows you to watch signal and noise levels, packet statistics, device configuration, and network parameters of your wireless network hardware. It was written by Jan Morgenstern and is regularly maintained. It allows you to display your WiFi signal strength in realtime. Installation and start You install wavemon with sudo apt install wavemon -y And start it with wavemon and a dashboard appears. If you can’t see the function keys at the bottom, you need to make your Terminal window larger. What the information means Let’s quickly run through the data points that you want to look at to understand better the WiFi quality that your digital picture frame enjoys. Signal strength Basically, the higher the signal strength, the more reliable the connection and higher speeds are possible. The signal strength is specified as -dBm (decibels related to one ...