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 Number References 1 PIC Pocessor PIC16F18324-I/P-ND U1 1 14 Pin Socket ED3114-ND U1 1 78L05 497-7268-ND U2

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.  Anyway, in one particularly frustr

Internet Explorer 11 (Windows 8.1) "Google Bug". Back Button hangs IE

I discovered this week that there is a bug in Google's web page that causes Internet Explorer 11 to hang when you click the back button. The specific scenario is that when you start on Google's web page, and go to a link of some sort, it can trigger this bug when you click back to return to google.  This is fairly well documented on some forums, in that it has been like this for a while, and Google seems unwilling, or unable, to modify their code to not trigger this bug. I do not consider it a IE11 bug as much as I consider it a problem with Google.  Microsoft should of course fix their issue, but also you would think that Google might take this seriously.  To trigger the issue, Go to google.com and search for something that takes you to a Microsoft page.  Example: "Exchange edge server".  Click on the first link and then click on any link on that Microsoft page.  Then click back twice.  The first "back" will work fine because it takes you to the original Mi