Unfolding Object Data Structure

by Mar 12, 2015

PowerShell 3.0 and later

Objects can contain nested properties, and the data you are after may be “somewhere” inside an object.

To display an object with all of its properties and subproperties expanded, convert it to JSON. This gives you a good textual representation of nested properties.

This example retrieves the current PowerShell process, then converts it to JSON, and sends the text to the clipboard. You can then paste it into any text editor:

Get-Process -Id $pid  | ConvertTo-Json | clip.exe

To control the recursion depth, use the -Depth parameter provided by ConvertTo-Json. The default value is 2 (so properties up to a nest level of 2 are displayed).

Twitter This Tip! ReTweet this Tip!