PowerShell Cmdlet - Out-GridView - Displaying Information In A Datagrid

Let's take an example of listing all the system drives of the computer.

gdr - PSProvider 'FileSystem'

Here 'gdr' is an alias for Get-PSDrive, which includes all of the virtual drives.

Suppose you have a requirement to select a few drives and pass it to the next command, then we might end up writing filter commands. But I personally prefer to use external window which displays the results in a grid view and support the feature of selecting multiple rows. We can also pass the selected values to the next command by using -passThru variable. Let's see how we can do it. We have to use the cmdlet Out-GridView.

Get-PSDrive - PSProvider 'FileSystem' | Out-GridView -passThru

As you see here, I am able to select any row or multiple rows and click OK to pass the selected values to next command.

Note

Computer should have .NET Framework 3.0 installed.