Vertical Grid View

by Sep 13, 2013

You can always pipe objects to Out-GridView and get a nice extra window with all of the object properties lined up as table. That's useful if you want to display a lot of objects.

If you just want to display one object with all of its properties, a vertical grid view would be a lot nicer. Actually, you can create your own by utilizing a so-called property grid. Here's a function:

Function Show-Object
{
    param
    (
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [Object]
        $InputObject,

        $Title
    )

    if (!$Title) { $Title = "$InputObject" }
    $Form = New-Object "System.Windows.Forms.Form"
    $Form.Size = New-Object System.Drawing.Size @(600,600)
    $PropertyGrid = New-Object System.Windows.Forms.PropertyGrid
    $PropertyGrid.Dock = [System.Windows.Forms.DockStyle]::Fill
    $Form.Text = $Title
    $PropertyGrid.SelectedObject = $InputObject
    $PropertyGrid.PropertySort = 'Alphabetical'
    $Form.Controls.Add($PropertyGrid)
    $Form.TopMost = $true
    $null = $Form.ShowDialog()
} 

Now, you can pipe any object into Show-Object, and it will display a vertical property grid. Even more interesting, all writeable properties are bolded, and you could actually change those right in the grid (watch out, changing things can be dangerous). And: when you select a property, many objects will show a detailed description in the window status bar:

Get-Process -id $pid | Show-Object

$host | Show-Object

Get-Item -Path $pshome\powershell.exe | Show-Object 

Twitter This Tip! ReTweet this Tip!