PowerShell Out-Gridview grants output insights

PowerShell Out-GridView Grants Output Insights

OK, then. I’m taking Matt Hester’s fabulous Learning PowerShell course over at LinkedIn. Right now, I’m into the third of three modules. I have to say: it’s been great! Yesterday, among lots of other incredibly useful nuggets, I learned about the Out-GridView cmdlet. To say that PowerShell Out-Gridview grants output insights for most cmdlets is like saying “The Grand Canyon is Big.” But that makes it no less true or interesting — to me, at least. Let me explain…

What PowerShell Out-Gridview Grants Output Insights Means

PowerShell cmdlets manipulate data objects. These have named properties. When you output them, you can see the values associated with all properties for an object instance (rows). You can also see the values associated with individual properties for all instances (columns).

Simply put, what Out-Gridview does is to grab the values associated with each instance’s properties and throw them up in a window like the one you see in the lead-in graphic. As you can see in the top line of that window this shows the results of the get-service cmdlet, from which the resulting objects’ Name, Status and RequiredServices property values are all shown. This is cool and helpful all by itself, but there’s more: a LOT more.

Working the GridView Window

Let’s call the windowed output from Out-Gridview a “GridView Window.” It’s actually an output from the Interactive Script Editor (ISE) that’s part of the overall PowerShell runtime environment.

In this GridView Window, you can click on any column head therein to sort the data by the values in that column. By default it comes sorted on whatever shows up in column 1 (aka “alphabetical order, by Name”). But you can also sort on Status, or RequiredServices as well.

Wait! There’s still more:

  • You can add all kinds of filters to the output shown in the Window
  • Types of filters include
    • contains (string or value partial matching anywhere)
    • does not contain (string or value absent)
    • starts with (initial string character matching)
    • equals (string or value exact match)
    • does not equal (string or value not matched or equal)
    • ends with (ending string character matching)
    • is empty (property has no value defined or is null)
    • is not empty (property has a value defined or is not null)
  • You can add as many filters as you like, change them as you go, and the GridView Window’s contents change dynamically to keep up
  • Data shows up as you type

Overall, this is a great way to examine data from cmdlet outputs in PowerShell. It means you don’t have to scroll up and down in the command window, nor do you have to save the data to a file and open it using your favorite editor. The gridview data is, however, evanescent (when you close the window, the data is gone). It doesn’t do away with piping output into files: it’s just a (temporary) alternative, but a darned good one!

Facebooklinkedin
Facebooklinkedin

4 thoughts on “PowerShell Out-GridView Grants Output Insights”

  1. Hi Ed.

    You can use the parameter -PassThru and then select the values you want using Click, Ctrl + Click or Shit + Click. Those values (objects) are passed through the pipe when you press OK or press Cancel and abort.

    1. Thanks for sharing: I have to laugh at your typo though “Shit + Click” is something I’ve never done, but can readily understand! LOL. Keep up the good work! =Ed=

  2. Cool. I hadn’t seen Out-GridView yet. I just used it to dump all the versions of DLLs in one of my directories to make sure the version numbers, descriptions etc are all correct. Here’s my command….

    Get-ChildItem -Path . -Filter ‘*.dll’ -Recurse | ForEach-Object { “{0}`t{1}” -f $_.Name, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($_) } | Out-GridView

Leave a Reply

Your email address will not be published. Required fields are marked *