“TUI” stands for “Terminal User Interface” and allows you to use the text capabilities of any console to create pseudo-graphical user interfaces, similar to the Norton Commander style of the 1990s. The advantage of TUIs is that they do not require graphical libraries, which are often OS-specific. WPF user interfaces, which we covered previously, for example, are limited to Windows only. TUIs, on the other hand, work cross-platform.

Before we dive into TUI, some background is helpful: TUI is a community-driven, open-source project (https://github.com/gui-cs/Terminal.Gui). Microsoft has been actively involved in improving terminal experiences on Windows through its own projects, such as Windows Terminal and the Microsoft.PowerShell.ConsoleGuiTools module, available on the PowerShell Gallery: https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools. These efforts aim to provide a fallback GUI for PowerShell 7.

The TUI framework is based on a binary (DLL file) that handles all the heavy lifting for you. However, this introduces new compatibility considerations you should be aware of: while WPF is limited to specific operating systems (Windows only), TUI is limited by the .NET framework version your PowerShell instance uses, since binaries must be compiled for a specific .NET version. Out of the box, TUI works only with PowerShell 7 (regardless of operating system); it does not work with Windows PowerShell.

That said, throughout this series, we’ll make TUI work in Windows PowerShell as well, and even introduce solutions for writing TUI scripts that run on all PowerShell versions across all operating systems.

Starting with TUI

In this first part, we’ll use TUI out of the box, so all examples require PowerShell 7. If you're using Windows PowerShell, either install PowerShell 7 to follow along, or use this part to familiarize yourself with the concepts. In a later part, we’ll show how to make TUI work in Windows PowerShell as well.

To get the TUI binaries, install the official “Microsoft.PowerShell.ConsoleGuiTools” module from Microsoft:

PS> Install-Module Microsoft.PowerShell.ConsoleGuiTools -Scope CurrentUser 

This module adds two new cmdlets:

PS C:\> Get-Command -Module Microsoft.PowerShell.ConsoleGuiTools

CommandType Name                Version Source
----------- ----                ------- ------
Cmdlet      Out-ConsoleGridView 0.7.7   Microsoft.PowerShell.ConsoleGuiTools
Cmdlet      Show-ObjectTree     0.7.7   Microsoft.PowerShell.ConsoleGuiTools

Originally, this module was a Microsoft initiative to add a pseudo-graphical version of Out-GridView to PowerShell 7, specifically for operating systems where classic WPF user interfaces aren't available. It works cross-platform—even on Windows. To see your first TUI interface, run the following line (in PowerShell 7, not Windows PowerShell):

PS> Get-Process | Out-ConsoleGridView

The result is a text-based “graphical interface” that displays all running processes. You can use Out-ConsoleGridView with the same parameters as Out-GridView. This creates a console-based TUI where the user can select one or more processes to stop:

PS> Get-Process | Where-Object MainWindowHandle | Out-ConsoleGridView -Title 'Select Process(es) to stop' -OutputMode Multiple | Stop-Process -PassThru 

Note how the TUI interface elegantly supports both keyboard and mouse input, and how it automatically redraws the “window” when you resize the console.

Press ESC to close the window, and ENTER to accept the current selection. If you select multiple entries while holding CTRL, a checkmark on the left marks the selected items.

Also note that this one-liner is for demonstration purposes only. Some processes—such as Windows apps like CalculatorApp—can not be closed using Stop-Process.

The module used here doesn't offer much more functionality out of the box, but wouldn’t it be great to tap into TUI and create your own custom interfaces, such as logon dialogs or interactive lists?
That’s exactly what we’ll cover in the next part.

Your ultimate PowerShell Cheat Sheet

Unleash the full potential of PowerShell with our handy poster. Whether you're a beginner or a seasoned pro, this cheat sheet is designed to be your go-to resource for the most important and commonly used cmdlets. The poster is available for download and in paper form.

Get your poster here!

Related links