Displaying Data in a Grid View Window Vertically

by Dec 12, 2017

Out-GridView always produces a table with one object per line:

Get-Process -Id $pid | Out-GridView

Occasionally, it would be more helpful to display the object properties vertically, with one property per line in a grid view window.

To do exactly that, take a look at Flip-Object: this function takes objects and splits them up into individual name-value-objects per property. They can then pipe to Out-GridView. This way, object properties can be examined in much more detail:

Get-Process -Id $pid | Flip-Object | Out-GridView

Here is the Flip-Object function that does the trick:

function Flip-Object
{
    param
    (
        [Object]
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
        $InputObject
    )
    process
    {
        
        $InputObject | 
        ForEach-Object {
            $instance = $_
            $instance | 
            Get-Member -MemberType *Property |
            Select-Object -ExpandProperty Name |
            ForEach-Object {
                [PSCustomObject]@{
                    Name = $_
                    Value = $instance.$_
                }
            }
        } 
          
    }
}

Twitter This Tip! ReTweet this Tip!