HOWTO: Show absolutely All Nested Properties of a PowerShell Object in a Treeview

If you’ve used PowerShell for length of time at all, I promise this HOWTO is going to be revelation and will fundamentally change how you use PowerShell.

PowerShell is full of objects.  All of those objects have properties.  Many of those properties have their own sub properties.  Those child properties can then still have even more properties underneath them. While it is fantastic that we have all of this data at our fingertips, it is often exceptionally difficult to know what’s available.  It’s a case of not knowing what you’re missing because you didn’t know about it in the first place.

To combat this, PowerShell includes an excellent command called Get-Member which shows what properties are available on an object.  The problem is, it doesn’t show sub properties and nor does it show the values of those properties. This combination makes searching for available data both frustrating and annoying.  I’m pleased to report I now have a solution for this problem!

I recently found myself having to learn about “JSON” for work.  In a nutshell, JSON is an alternative to XML and is a text based representation of data.  To work with JSON, PowerShell includes a cmdlet called ConvertTo-JSON. By complete accident I discovered that this cmdlet has a very interesting capability.  If you pipe any object into it, it will spit out absolutely everything PowerShell knows about that object, nested sub properties and all.

I then did some research and discovered a free standalone tool (no installation required) called jsonview.exe from CodePlex.  This tool provides a graphical tree view of JSON data.  Can you see where this is going? Wouldn’t it be amazing if you had a nice graphical interface to view all of the data inside of an object, regardless of how far down it was nested?

Consider the following example.  We have a cmdlet called Send-Email that isn’t working properly.  When we try to use it, all we get is an error “Unable to connect to the remote server”.

The question is?  What server?  And why can’t it connect to it?

image

 

Now you may be aware that PowerShell automatically writes all errors to a variable called $Error.  If we view that without any additional parameters, we get the same error message displayed to us earlier:

image

You may be aware that you can use the Get-Member cmdlet to view the specific properties available which is where we’ll find all of the actual useful details.  But as you can see, it can be difficult to understand:

image

Now only that, but this is only showing the first level of properties.  Each one of those properties may have sub properties underneath them.  Sorting through that is a giant pain.  Thankfully you’ll never have to do it again.

Instead, use the new cmdlet I am providing to you today called “Show-AllProperties

image

Wait, it doesn’t appear to have done anything.  Oh but it has!  A new GUI Window has opened with a wonderful tree view showing all of the properties and their values!

image

Look at all of this detail!

From this we know that the Send-Mail command actually calls a command called Send-MailMessage on line 5 of the script.  It tries to connect with a username svcmail and a password of Sup3rS3cr3t (in plain text!) and is trying to connect to mail.microsoft.com on port 26.  That gives us more than enough information to troubleshoot the connection!

But this command is useful for so much more.  Any time you need to view what’s in an object, you can use this cmdlet!  Here is another example.  If you’ve spent any time with PowerShell and the Event Viewer you know that if you view an Event in the built in Windows Event Viewer, you have an “XML” tab that occasionally gives you additional valuable troubleshooting detail.  Unfortunately, there is no easy way of displaying this data in PowerShell – until now.

I have written a PowerShell command called Get-EventLogData that returns not only all of the regular event details but also all of the “EventData” (aka XML) details.  Let’s view these results in a GUI, shall we?

Get-EventLogData –LogName Security–EventID 5152 | sap

image

As you can see above, the default properties that are returned by the Get-EventLog cmdlet do not include the EventData which is often where all the useful information lies.  However my Get-EventLogData includes this data.  Then by passing it to the Show-AllProperties cmdlet makes it trivially easy to identify.

This Show-AllProperties function has fundamentally changed how I use PowerShell and has made it far more enjoyable and productive to use.  If you’d like this for yourself, here is what you need to do:

1) Download JsonView from https://jsonviewer.codeplex.com/

2) Copy and paste the following script into your default Powershell profile at “C:\windows\system32\WindowsPowerShell\v1.0\profile.ps1” (you may need to create the file)

3) Update the $JSONViewPath to the location of the application

2 comments

    • Annoymous on October 7, 2017 at 8:43 pm
    • Reply

    Thank you! This works very well. I look forward to trying it out even more.

    I’ve used two other PowerShell viewers for recursive/nested objects:
    1) “PSObjectBrowser” is very powerful, but also very temperamental
    2) “Show-Object” always shows the entire path of whatever nested object or property you are looking at (e.g. “$_.Exception.Response.StatusCode.value__”), which is great for copying and pasting

    • Gregory Pearl on August 7, 2018 at 2:00 pm
    • Reply

    I know that this post is rather old but when I download the archive from Codeplex there no exe application. I have been unable to find a download on the internet.

Leave a Reply

Your email address will not be published.