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.
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
The cmdlet lets you select multiple items by default and automatically passes them to the pipeline. Out-ConsoleGridView works cross-platform as well.
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.
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.
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.
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.
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
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.
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.
Thank you for sharing this Jeff. I will definitely play around with this module.