Ezine 192 – PowerShell 2.0 Out-GridView

PowerShell 2.0 Out-GridViewPowerShell Out-GridView

Out-GridView provides a better way for PowerShell to present tabulated information.  It works particularly well for displaying data returned by get-Service or get-Process.

PowerShell Out-GridView – New in Version 2.0


This Week’s Secret

There are general cmdlets such as get-Help and get-member that you need to master when you perform basic PowerShell research.  And there are numerous dedicated cmdlets such as restart-Computer that you need to understand before you can complete a specialist tasks  However, Out-Grid is in a class of it’s own, not because of its technical sophistication, but just because it will give you that ‘ah ha’ moment.  As a bonus, the verb ‘Out’ will remind us of other handy members of the output family such as out-File and out-Printer.

Introduction to Out-GridView

If you have not seen out-GridView before it could be because this is a new cmdlet in PowerShell Version 2.0. As with any new cmdlet, before we put out-GridView to work it’s worth calling for help so that we can check the syntax and seek out interesting parameters.

get-Help out-GridView -full

Note 1:  Because I want to see examples, I rarely use get-Help without appending the -full switch.  In this case help alerted me to sorting the columns by simply double-clicking their heading.  In addition, it was only by reading the help file that I realized the benefit of using the ‘Search’ box as a filter.

Note 2:  The only problem I have encountered with out-GridView is spelling the noun.  Grid View is wrong, and omitting View is another fatal sin, Out-Grid does not work.  Remember it’s one word, gridview as in Out-GridView.

Example 1: Out-GridView and Get-Service

get-Service | out-GridView

Note 1:  Please remember the pipe (|), especially when you get too ambitious, and something goes wrong with your complex experiment.

Note 2:  You can also copy the data displayed by out-GridView and paste it into Excel.  Numeric data often benefits from further manipulation by the spreadsheets functions.  I find that the old keyboard shortcuts such as Ctrl + a are handy for selecting all the rows.

Example 2: Out-GridView and Get-Process

This example illustrates the benefits of adding extra PowerShell code in order to control the headings.  For example, we want the name of each process in the first column.

get-Process | select-Object -property name, workingSet, peakWorkingSet | out-GridView

PowerShell Out-GridView

Note 1:  Remember that you can sort on any of the columns simply by double-clicking.

Note 2:  It surprised me to discover that you can also drag and drop the columns to re-order the data.  Resizing the columns works intuitively, just like Excel.PowerShell Out-GridView

Note 3:  Out-GridView has a search box that you don’t normally get with get-Process.  One use of this Search capability is to filter the data.

Example 3: Out-GridView Show in Groups

Another surprising feature of out-GridView is how we can group items.  For example, with get-Service you can aggregate the services that are stopped.  Just right-click on the heading and see if it supports ‘Show in Groups’, see screenshot to the right.  All in all, out-Grid means that you can manipulate data quickly on the fly, this saves having to revisit the code and changing the properties or adjusting the grouping syntax.

Guy Recommends: WMI Monitor and It’s Free!Solarwinds Free WMI Monitor

Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems.  Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your scripts.

Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory or Exchange Server. Give this WMI monitor a try – it’s free.

Download your free copy of WMI Monitor

Example 4: Import XML Files

One more pleasant revelation, if you import an XML file then you can improve the way the data displays by piping its contents into out-GridView.  Assuming you have a suitable xml file called services.xml, try this:

Import-CliXML C:\PShell\services.xml | Out-GridView

Note 1:  I don’t want you to go away thinking that out-GridView is only suitable for get-Service, it’s just that all Windows computers have services, and their data shows off this display cmdlet in it’s best light. 

Other Members of the ‘Output’ Family

While out-GridView is easy to understand, it maybe that you already know other members of the ‘Output’ family of cmdlets.  My point is that if you have already used out-File then you will know what to expect from out-GridView.  On the other hand, if this is all new territory, then you can apply knowledge of out-GridView to out-Printer.

get-Command -verb out 



Summary of PowerShell’s Out-GridView

PowerShell v 2.0 has a lovely new cmdlet called out-GridView, what this does is take the output from another command and present it in a new window where the data is displayed in an interactive table.  Take the time to research the ‘Search’ box and discover how to ‘Show in Groups’.

Guy Recommends: Tools4ever’s UMRAUMRA The User Management Resource Administrator

Tired of writing scripts? The User Management Resource Administrator solution by Tools4ever offers an alternative to time-consuming manual processes.

It features 100% auto provisioning, Helpdesk Delegation, Connectors to more than 130 systems/applications, Workflow Management, Self Service and many other benefits. Click on the link for more information onUMRA.

If you like this page then please share it with your friends


See more Microsoft PowerShell file tutorials:

PowerShell Home   • Add-Content   • Get-Content   • Set-Content  • PowerShell -Filter   • Test-Path

PowerShell Get-ChildItem   • Get-ChildItem -Include   • Get-ChildItem -Exclude   • Compare-Object

PowerShell Registry  • Get-Credential  • PowerShell ItemProperty  • PowerShell ItemPropery GCI

Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.