The Out-Gridview Cmdlet

The information in this article was written against the second Community Technology Preview (CTP2) of Windows PowerShell 2.0. This information is subject to change in future releases of Windows PowerShell 2.0.

Filter With Out-GridView

The first CTP release of Windows PowerShell included a new cmdlet – Out-GridView – that enabled you to easily display output in a grid. And that was only for starters: this new grid also enabled you to sort by any given property; to display items in groups; and even to use keyword searches to do rudimentary filtering. What more could you possibly ask for in a cmdlet?

And the truth is, maybe you couldn’t think of anything more to ask from Out-GridView. But that’s OK; the Windows PowerShell team went ahead and delivered more anyway.

In the Windows PowerShell 2.0 of Windows PowerShell the PowerShell team has made a small but incredibly useful addition to the grid created by Out-GridView: they’ve added true filtering capabilities. Here’s what the grid looks like in the latest CTP release (after using the command Get-Process | Out-GridView):

So what, you say? Looks pretty much like the old grid, you say? Well, maybe. But try clicking the Filter button in the upper right-hand corner of the window. After clicking Filter click Add Criteria:

See the dropdown list that appears? That’s a list of all the properties displayed in the grid. Let’s say you’d like to filter the display by process Handles. No problem; just choose Handles from the dropdown, click OK, and you should see something like this:

This just keeps getting better and better, doesn’t it? When you select a property value from the dropdown list the grid will then give you an opportunity to specify the criteria for this filter. (And the grid is smart, too: the choices available to you will reflect the data type of the chosen property.) For demonstration purposes, we’re interested in processes that have 500 or more handles. With that in mind, click the label is between and select greater than or equal to. Type 500 in the text box and then click Apply; your display should change to look something like this:

Now what more could you ask for in a cmdlet?

Well, how about this: click Add Criteria to add a second criteria to the filter. This time we’re going to add an AND clause that further restricts the display to process that have 500 or more handles and a process name of svchost. Fill in the criteria, click Apply, and, voilà:

Very nice indeed.

Incidentally, it’s easy enough to get back the original display, the one that listed information for all the processes; all you have to do is click the Clear All button:

All that, and without even having to ask for it.