Tag Archives: Out-Gridview

Browsing PowerShell Commands

Whenever I’m exploring a new PowerShell module or snapin, one of the first things I do is list all of the commands found within the module.

You can specify either a module or a snapin. Use the -module parameter for both. However, for larger modules, I’ve realized I need a better way to browse the commands. For example, I might need to see them organized by verb or noun. That information is included with the Get-Command expression. I simply have to ask for it. Here’s a more thorough command and the result.


I included the command type because some modules might contains cmdlets and functions. I could revise this expression and insert a sort command. But that’s too much typing. Especially if I want to sort and re-sort. Instead, I’ll pipe this command to Out-Gridview.


Now I have a sortable and filterable view of all the commands. Plus, it is in a separate window so I have my prompt back and get help for listed commands. I even decided to build a quick-and-dirty function.

Because the module or snapin name can include a wildcard, I added the module name to the output. Now I have a tool to grab all the commands from a module or set of modules and I can filter and browse all I want without having to retype or revise commands at the prompt.

Friday Fun: View Objects in a PowerShell GridList

One of the things that makes PowerShell easy to learn is discoverability. Want to know more about a particular type of object? Pipe it to Get-Member. Or if you want to see values pipe it to Select-Object.

That’s not too bad. Or you can pipe to Out-Gridview.

However, for a single object it isn’t easy to see everything .

What would be easier, at least for me, is to use Out-Gridview but see the properties in a list like I can with Select-Object. So I wrote an advanced function to do just that. The function takes an incoming object, creates a hashtable based on the object’s properties and then displays the hashtable in Out-Gridview.

The function will accept multiple objects, which is why I have a data array to handle multiple piped in objects. But it really works best with a single object. In the Process scriptblock I pass the object to Get-Member to retrieve properties. Then the function creates a hashtable where the key is each property and the value is the corresponding value from the object.

At this point I could simple write the hashtable to Out-Gridview, but the column headings would say Name and Value. It’s a small detail but I use a hashtable with Select-Object to rename “Name” to “Property”. By the way, you may have noticed this line.

That isn’t a typo. If I pipe multiple objects, then $data will be an array of hashtables and so I need to get an enumerator for each one. But with this function now I get the display I want.


There really isn’t any filtering to do but you can click on the column headings to sort. Or your can run Out-Gridlist with -passthru so you can select properties and pass them through to the pipeline.

I hope you find this useful. Enjoy responsibly.

Friday Fun A Graphical PowerShell History Picker

One of my favorite features in PowerShell 3.0 is that you can select items in Out-Gridview which will then pipe the object back to the pipeline. One way I’ve been using this is as graphical “picker” for command history. I use Get-History, actually its alias h, all the time. Once I know the history number I then use Invoke-History, or its alias r. Now, with Out-Gridview, which has an alias of ogv, I can sneak in a little something extra.

I realize this is cryptic but when using the shell interactively efficiency is paramount. This is the actual full command.

I’ll get something like this:


I can select an item, click OK and the command will run back in my console. There are a few downsides, but remember this is a Friday Fun article. First, if you cancel, PowerShell will invoke the last command again. Also, as written if you select multiple items, which you could with -Passthru, you’ll get an error because Invoke-History won’t accept multiple entries. You could force Out-Gridview to only allow a single selection.

Or you could use Foreach to handle multiple selections.

Be aware that when you run multiple commands in the same pipeline formatting can get a little screwy so I would probably stay way from it.

One more way you might use this is with Invoke-Expression (iex) instead of Invoke-History. The history object has a commandline property which you could invoke.

This will also handle multiple commands. If you cancel from Out-Gridview, Invoke-Expression will throw an exception but at least it won’t try to re-run the last command which is probably better.

Again, these are all “quick and dirty” commands to have fun with from a PowerShell prompt.