Go to ...

RSS Feed

September 22, 2020

Out-Gridview – Most versatile PowerShell cmdlet?


According to Microsoft Docs, “the Out-GridView cmdlet sends the output from a command to a grid view window where the output is displayed in an interactive table“. In my opinion, it is the most versatile and practical of all PowerShell cmdlets. As all cmdlets do, it tells PowerShell to “do this with that”  (cmdlet syntax is Verb-Noun), Out being short for Output. In all its simplicity, it tells PowerShell to send command line output to a new window, and presents it in a table (grid) layout.

Here’s one simple example. I have ISO images in various folders on an external drive I:. To list all of them in a grid, I enter the following command:

Get-ChildItem -Path "I:\*.iso" -Recurse | Out-GridView

Get-ChildItem cmdlet with -Recurse switch makes PowerShell go through all the folders on I: drive, after which the results list is piped (pipe character = |) into a table.

OK, there’s nothing special there. I could have gotten the same list also without piping the command into a grid, directly in the PowerShell window. The magic happens when using the -PassThru switch with the Out-GridView cmdlet. Let’s list all ISO images on the I: drive, output that list as an interactive table which lets us select items from the list, and then finally move those selected ISO images into a folder on my NAS:

Get-ChildItem -Path "I:\*.iso" -Recurse | Out-GridView -PassThru | Move-Item -Destination "\\NAS\Kari\Insider ISO Images"

The -PassThru switch sends the selected items to the next cmdlet,  which in this case is named Move-Item:

Click screenshots to open enlarged in a new tab.

Easy! All of the selected items — ISO images in this case — were moved to my NAS.

Another quite practical example is something I always do when I have customized a Windows image in Audit Mode, and have captured it. Next, I enable some additional features. In the title image for this story (see it enlarged here), I mount a Windows image in folder C:\Mount, then list all additional Windows features that are disabled on that image, and enable Hyper-V and the Windows Subsystem for Linux features. I then dismount that image, and save those changes.

Using Out-GridView with -PassThru makes this easy:

Get-WindowsOptionalFeature –path C:\Mount | Where-Object {$_.State –eq “Disabled”} | Out-GridView -PassThru | Enable-WindowsOptionalFeature

I select the features I want to enable, and click OK to pipe them into the Enable-WindowsOptionalFeature cmdllet:

The more you use PowerShell, the more use you can find for the Out-GridView cmdlet. It’s really quite amazing and helpful.

That’s it this time!

Kari

Author: Kari Finn

A former Windows Insider MVP, Kari started in computing in the mid 80’s writing code for VAX / VMS systems. Since then, he’s worked in a variety of IT positions. He specializes in Windows image capture, customization, repair and deployment as well as Hyper-V virtualization. Kari is a proud Team Member at number #1 Windows site TenForums.com.

Leave a Reply

More Stories From Kari's Blog