Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell 7 ConsoleGridView

Posted on February 3, 2022February 3, 2022

Last night during my presentation for the Research Triangle PowerShell User Group, I briefly demonstrated a PowerShell 7 command called Out-ConsoleGridView. This command will not run in Windows PowerShell. If you haven't thought about running PowerShell 7, maybe you'll reconsider after learning more about this tool.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

You all know about Out-Gridview, which also works in later versions of PowerShell 7. Out-ConsoleGridview, which has an alias of ocgv, will take pipelined input and display it as a table in the console. You can filter and select objects just as you do with Out-Gridview, but there is no separate display. The output remains in your console session.

You need to install a module from the PowerShell Gallery in a PowerShell 7 session to get this command.

install-module microsoft.powershell.consoleguitools

The command is simple enough to use.

get-process | Out-ConsoleGridView
Out-ConsoleGridView

The cmdlet lets you select multiple items by default and automatically passes them to the pipeline. Out-ConsoleGridView works cross-platform as well.

Out-ConsoleGridview on Linux

One thing to be aware of is that the cmdlet takes its color cues from the hosting application. If you run PowerShell inside Windows Terminal, you might have a different experience based on the color scheme you are using.

Out-ConsoleGridview with a different color scheme

From what I can tell, the background color is based on whatever the host decides is "blue." The status bar is "brightblack," and the selection highlight is "cyan." In PowerShell 7, you can see these values with $PSStyle.

Out-Gridview color scheme

You'll see different renderings of these values in Windows Terminal based on your color scheme. There is no way to alter the color scheme used by Out-ConsoleGridView itself. Although this is an open issue in the cmdlet's GitHub repository. The best you can do is edit values in the Windows Terminal settings.json file for the profile's color scheme.

Like Out-Gridview, you can perform additional filtering of the output. Be careful. The filtering treats each line item as a string. The filtering is nothing more than a pattern match like 'co'. Although, you can use fancy regex patterns.

Out-ConsoleGridView filtering

As I mentioned, you can select items with the space bar, and pressing Enter passes the object back to the PowerShell pipeline. This offers some intriguing possibilities. Here's one example.

$events = Import-Csv C:\scripts\company.csv | 
Out-ConsoleGridView -title "Select computers to check" | 
Foreach-Object -Parallel {
    Get-Winevent -LogName System -max 500 -ComputerName $_.computername
}

I'm going to import data from a CSV file and pipe it to Out-ConsoleGridView.

Out-ConsoleGridView object picker.

The selected objects are passed back to the pipeline, where I run a Get-Winevent command in parallel. My demonstration is only using two computers and getting a small number of event log records. But you could easily scale this out.

I can then take the results and view them in Out-ConsoleGridview.

$events | Select-Object -Property Machinename,TimeCreated,LevelDisplayName,Message | 
Out-ConsoleGridView  | Format-List
Out-ConsoleGridview as a viewer

I'm using the Filter feature to get Errors. I'll select both entries and press Enter, which sends the results to Format-List, making the event log record easier to read.

event log errors

There is also an issue about adding a way to select all items in the list. Currently, you have to select each one manually.

I use this command often. One of the drawbacks with Out-Gridview is that I can't control the size, and often on my 44" monitor, the window is stretched almost the entire width of the monitor. I like having the grid view limited to my console window.

The last item to mention is that you can't use Out-ConsoleGridview in a remoting session. But that doesn't preclude you from using remoting and running Out-ConsoleGridview on your desktop.

$svc = "dns","adws","kdc","w32time","netlogon"
Invoke-Command { Get-Service $using:svc } -computername dom1,dom2 |
Sort-Object Name | Select-Object Status,Name,DisplayName,StartType,PSComputername | Out-ConsoleGridView -Title "Domain Controller Services" -OutputMode None

Naturally, I encourage you to give this command a spin and try it out for yourself.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

2 thoughts on “PowerShell 7 ConsoleGridView”

  1. Pingback: PowerShell 7 ConsoleGridView - The Lonely Administrator - Syndicated Blogs - IDERA Community
  2. Marco says:
    February 6, 2022 at 4:23 am

    Thank you for sharing this Jeff. I will definitely play around with this module.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d