Out of the box, TUI works only in PowerShell 7, leaving Windows PowerShell users behind. That’s unfortunate, because TUI is a powerful GUI concept. There is no technical reason why TUI shouldn't work in Windows PowerShell—the only limitation is that the TUI source code (https://github.com/gui-cs/Terminal.Gui) has only been compiled against .NET Core. Apparently, no one has taken the time to compile it against the classic .NET Framework.

To make TUI available in both Windows PowerShell and PowerShell 7, we just need two versions of the binaries: one compiled against .NET Core and one compiled against the full .NET Framework.

I’ve done this work for you. As both a proof of concept and a template for your own projects, simply install the module TuiCredential from the PowerShell Gallery (https://www.powershellgallery.com/packages/TuiCredential)—in Windows PowerShell, PowerShell 7, or both:

PS> Install-Module -Name TuiCredential -Scope CurrentUser  

Once the module is installed, try out the TUI interface by running the following command:

PS> Show-CredentialDialog 

This command invokes TUI and displays a custom dialog that prompts for a user credential. The current username is prefilled—just type your password and press ENTER. Show-CredentialDialog returns a ready-to-use PSCredential object that you can immediately use to authenticate with other systems.

You can also use parameters to customize the dialog:

PS> Show-CredentialDialog -Title 'Log on to File Server 12' -UserName serviceaccount1 -AllowToggle 

This inserts a custom title, prefilled username, and a toggle button to switch between masked and clear text input.

Loading Binary on Demand

When you look inside the module, you'll see that it includes two sets of DLLs in separate subfolders—one for Windows PowerShell and one for PowerShell 7.

When the module is imported, it runs init.ps1:

# determine whether we are in Windows PowerShell or PowerShell 7
$folder = if ($PSVersionTable.PSVersion.Major -le 5)
{
  Join-Path -Path $PSScriptRoot -ChildPath Binaries
  Write-Verbose "Loading .NET Framework Binaries"
}
else
{
  Join-Path -Path $PSScriptRoot -ChildPath BinariesPs7
  Write-Verbose "Loading .NET Core Binaries"
}

$dllPath = Join-Path -Path $folder -ChildPath Terminal.Gui.Dll
Add-Type -Path $dllPath 

Depending on the PowerShell platform, it loads the types from the appropriate DLL, ensuring that all subsequent TUI code runs correctly—regardless of which version of PowerShell you're using.

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