Displaying Object Properties One per Line

by Sep 3, 2015

Sometimes you may want to get a good overview of the data contained in an object. For example, if you query the PowerShell process and display it in a grid view window, you can see the object content:

Get-Process -Id $pid | Out-GridView

But can you really? The object is displayed in one line, and a hidden limitation in a grid view window will only show a maximum number of columns of 30. Since all is one line, you cannot search for properties, either, because always the entire line is selected.

Wouldn’t it be nicer to display the object properties line by line? Here is how:

$object = Get-Process -Id $pid
($object | Get-Member -MemberType *Property).Name | 
  ForEach-Object { 
      
      New-Object PSObject -Property ([Ordered]@{Property=$_ Value=$object.$_ }) 
  
  } | Out-GridView 

Now, each property gets its own line, and you can display as many as you want, and search for a particular property by content.

Twitter This Tip! ReTweet this Tip!