PowerShell interactive filter with Out-GridView

Recently, during the first meeting of our new south-german PowerShell Usergroup, Rolf Masuch showed us a nice feature which I didn´t know: Using Out-GridView as interactive filter.

Here is how to do it:

The magic parameter is –PassThru !

If you want the user to select, let´s say, some services to stop, you just can get the output of Out-GridView with the parameter PassThru:

$result = Get-Service | Out-GridView –PassThru

image

will show you a grid of all your services:

image

By filtering in the grid and pressing OK, you can select which services should land in $result:

image

$result now only holds the services that were in the filter in your grid:

image

Now you could use $result for stopping the user selected services

image

I think this is a nice little option if you have some interactive scripts.

Have a nice day!

Christian

Leave a Reply

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