---
title: "How to Craft a Modern PowerShell Message Box"
description: "Discover all the modern ways to craft a PowerShell Message Box and get away from the VBScript methods of old in this updated how-to!"
canonical: "https://adamtheautomator.com/powershell-message-box/"
---

# How to Craft a Modern PowerShell Message Box

> Discover all the modern ways to craft a PowerShell Message Box and get away from the VBScript methods of old in this updated how-to!

Source: https://adamtheautomator.com/powershell-message-box/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Craft a Modern PowerShell Message Box](https://adamtheautomator.com/wp-content/uploads/2022/12/powershell-message-box.jpg)

# How to Craft a Modern PowerShell Message Box

[![](https://secure.gravatar.com/avatar/b4cd4a109fc359fca6ccc8a192dd75bf9a440677bb2a87da8c23f48d76b3bb39?s=192&d=mm&r=g)Edem Afenyo](https://adamtheautomator.com/author/edem-afenyo/)2 January 20235 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Crafting a PowerShell Message Box via the Terminal.Gui](#crafting-a-powershell-message-box-via-the-terminalgui)
*   [Creating a PowerShell Message Box with Avalonia](#creating-a-powershell-message-box-with-avalonia)
*   [Installing Avalonia](#installing-avalonia)
*   [Creating a Message Box](#creating-a-message-box)
*   [Conclusion](#conclusion)

Are you looking for a graphical way to notify users of your scripts or gather feedback? The world has changed since the good old days of [Windows.MessageBox](https://ss64.com/ps/messagebox.html)\-based message boxes. But luckily, a modern PowerShell message box is up to the task. How?

In this tutorial, you will learn two of the newer and more powerful tools you can use to generate a PowerShell message box, [Terminal.Gui](https://github.com/gui-cs/Terminal.Gui) and [Avalonia](https://avaloniaui.net/). Between these two tools, you can not go wrong.

Read on and craft message boxes that users simply cannot ignore!

## Prerequisites

This tutorial will be a hands-on demonstration. To follow along, be sure you have the following:

*   [PowerShell 7+](https://adamtheautomator.com/powershell-7-upgrade/) – This tutorial uses PowerShell 7.3.

Related:[PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

*   A [Fedora](https://getfedora.org/) machine – This tutorial uses Fedora 35 (with PowerShell installed) to create and launch the Terminal.Gui-based message box, though this also will work in Windows as well.

Related:[Getting Advantage of PowerShell on Linux: A Beginner’s Guide](https://adamtheautomator.com/powershell-linux/)

*   A Windows machine – This tutorial uses [Windows 10](https://en.wikipedia.org/wiki/Windows_10) to create and launch the Avalonia-based message box

## Crafting a PowerShell Message Box via the Terminal.Gui

The Terminal.Gui tool provides Terminal User Interfaces (TUI), which lets you create a PowerShell message box using the terminal. But before creating a PowerShell message box, you must first install Terminal.Gui on your system.

1\. Log in to your Fedora machine, open the terminal, and run the `pwsh` command below to access the PowerShell prompt.

```
pwsh
```

![powershell message box - Accessing PowerShell via terminal](https://adamtheautomator.com/wp-content/uploads/2022/12/image-383.png)

Accessing PowerShell via terminal

2\. Next, execute the [`Install-Module`](https://learn.microsoft.com/en-us/powershell/module/powershellget/install-module) cmdlet below to install the [`ConsoleGuiTools`](https://www.powershellgallery.com/packages/Microsoft.PowerShell.ConsoleGuiTools) module. This module gives you access to the Terminal.Gui tool in `PowerShell`.

```powershell
Install-Module Microsoft.PowerShell.ConsuleGuiTools
```

Type **Y** and press Enter when prompted, as shown below, to trust the source repository of the module and start the installation.

![Installing Terminal.Gui](https://adamtheautomator.com/wp-content/uploads/2022/12/image-384.png)

Installing Terminal.Gui

3\. Once installed, create a new file in your favorite text editor, populate the following script into the file, and save it. You can name the script as you like, but this tutorial’s choice is _prompt-test.ps1_.

The code below tells PowerShell to launch a message box with the `Query` method of the `Terminal.Gui.MessageBox` object. `Query`, which is the focal point of the code below, takes at least three arguments, as follows:

```powershell
Query(title, message, buttons)
```

<table><tbody><tr><td><strong>Arguments</strong></td><td><strong>Description</strong></td></tr><tr><td>Title</td><td>The message box’s title is set to “Important” for this tutorial.</td></tr><tr><td>Message</td><td>The text to display to the user of your application. For this tutorial, the message is set to “Do you love PowerShell?”.</td></tr><tr><td>Button</td><td>The names of the buttons in the message box, in this case, Yes and No. Each will be assigned an internal numerical value (0 and 1) based on its position. That value will be returned to the script for onward processing.</td></tr></tbody></table>

```powershell
# Import the module
Import-Module Microsoft.PowerShell.ConsoleGuiTools

# Load the Terminal.Gui assembly
$module = (Get-Module Microsoft.PowerShell.ConsoleGuiTools -List).ModuleBase
Add-Type -Path (Join-path $module Terminal.Gui.dll)

# Initialise Terminal.Gui
[Terminal.Gui.Application]::Init()

# Create a message box and assign the result of a selection to a variable
$result = [Terminal.Gui.MessageBox]::Query("Important", "Do you love PowerShell?", @("Yes", "No"))

# Utilise the result of the selection
# Write output to the terminal window and close the message box
if ($result -eq 0)
{
    # Shutdown the GUI application gracefully
    [Terminal.Gui.Application]::shutdown()
    write-host("It's good you love PowerShell!")
}
if ($result -eq 1)
{
    # Shutdown the GUI application gracefully
    [Terminal.Gui.Application]::shutdown()
    write-host("Too bad, PowerShell is great. Give it a chance.")
}
```

> 💡 _Besides creating a script, note that you can invoke a message box or other visual user interface elements directly from the prompt._

4\. Now, switch to your PowerShell prompt, and run the below command to execute the script (`*prompt-test.ps1*`) from the working directory (`.`)

Related:[How to Run a PowerShell Script From the Command Line and More](https://adamtheautomator.com/run-powershell-script/)

```powershell
./prompt-test.ps1
```

If the script works, a small message box appears on your screen, as shown below.

![Viewing the message box](https://adamtheautomator.com/wp-content/uploads/2022/12/image-385.png)

Viewing the message box

5\. Lastly, select an option, **Yes** or **No,** and see what response you will get in your PowerShell prompt. You can use the mouse or the keyboard for navigation.

![Selecting a message box button ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-386.png)

Selecting a message box button

Based on your chosen option, you will have the appropriate response in your PowerShell prompt, as shown below.

![Viewing the result of selecting a message box option](https://adamtheautomator.com/wp-content/uploads/2022/12/image-387.png)

Viewing the result of selecting a message box option

## Creating a PowerShell Message Box with Avalonia

If you are more into seeing a Windows message box, Avalonia is an excellent option. You will generate a message box using Avalonia, which provides a full-blown GUI window.

But first, you must register [NuGet](https://www.google.com/search?q=nuget&oq=nuget&aqs=chrome..69i57.602j0j1&sourceid=chrome&ie=UTF-8) as a package source. Avalonia and other necessary packages will be downloaded through NuGet.

Log in to your Windows machine, open [PowerShell as administrator](https://adamtheautomator.com/powershell-run-as-administrator/), and run the following command. This command registers ([`Register-PackageSource`](https://learn.microsoft.com/en-us/powershell/module/packagemanagement/register-packagesource)) `NuGet` as a package source under `MyNuget` (or any name you prefer).

```powershell
Register-PackageSource -Name MyNuGet -Location <https://www.nuget.org/api/v2> -ProviderName NuGet
```

![Registering NuGet as a package source](https://adamtheautomator.com/wp-content/uploads/2022/12/image-388.png)

Registering NuGet as a package source

### Installing Avalonia

Before taking advantage of Avalonia, like Terminal.Gui, you first have to install Avalonia on your machine.

1\. Execute the [`Install-Package`](https://learn.microsoft.com/en-us/powershell/module/packagemanagement/install-package) cmdlet below to install the [`netstandard.library`](https://www.nuget.org/packages/NETStandard.Library/) package for your user account only. This package is a dependency for Avalonia.

The command below turns on the `-SkipDependencies` switch to avoid errors with non-critical `netstandard.library` dependencies.

```powershell
Install-Package -Name netstandard.library -Scope CurrentUser -SkipDependencies
```

Type **A** and press Enter to confirm the installation when prompted, as shown below.

![Installing Avalonia dependencies](https://adamtheautomator.com/wp-content/uploads/2022/12/image-389.png)

Installing Avalonia dependencies

2\. Next, run `Install-Package` to install the `avalonia` package for the `CurrentUser` only. Installation for the current user allows you to carry on without an elevated command prompt.

```powershell
Install-Package -Name avalonia -Scope CurrentUser
```

Confirm the installation when prompted, as shown below, and you will see a list of dependencies and packages installed along the way.

![Installing Avalonia](https://adamtheautomator.com/wp-content/uploads/2022/12/image-390.png)

Installing Avalonia

3\. Now, run the below command to install the `PSAvalonia` package, which provides direct PowerShell bindings for Avalonia.

```powershell
Install-Package -name psavalonia -scope CurrentUser 
```

![Installing the PSAvalonia package](https://adamtheautomator.com/wp-content/uploads/2022/12/image-391.png)

Installing the PSAvalonia package

### Creating a Message Box

With Avalonia and its dependencies installed, you can create a modern PowerShell message box. You will create a PowerShell script that functions similarly to your script for Terminal.Guit o create your message box.

1\. Create a new file, add the code below, and save it as a PowerShell script. You can name the script as you prefer, but this tutorial uses _msgbox.ps1_ as the script name.

This code functions similarly to your script for Terminal.Gui, but this time, the message box is designed via XAML.

```powershell
# Design a message box
$Xaml = '<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="300" d:DesignHeight="200"
		Width="300"
		Height="200"
        x:Class="avaloniaui.MainWindow"
        Title="Important">
   <StackPanel>
	<TextBlock Margin="10" Name="msg" VerticalAlignment="Top" Width="200" Height="25"> Do you love PowerShell? </TextBlock>
	<Button Width="160" Name="button1">Yes</Button>
	<Button Width="160" Margin="10" Name="button2">No</Button>
	
    </StackPanel>
</Window>'

# Convert XAML description to Avalonia object
$window = ConvertTo-AvaloniaWindow -Xaml $Xaml

# Map Avalonia controls to PowerShell variables
$Button1 = Find-AvaloniaControl -Name 'button1' -Window $Window
$Button2 = Find-AvaloniaControl -Name 'button2' -Window $Window

# Handle responses once the message box is loaded. 
# Write to the terminal and close the message box.
$Button1.add_Click({
	write-host("It's good you love PowerShell!")
	$window.close()		
	})
$Button2.add_Click({
	write-host("Too bad, PowerShell is great. Give it a chance.")
	$window.close()		
	})
	
# Show message box
Show-AvaloniaWindow -Window $Window
```

2\. Next, run the `pwsh` command below to execute your script (`msgbox.ps1`).

```powershell
pwsh .\msgbox.ps1
```

3\. Now, select any option from the message box that appears.

![Selecting an option from the message box ](https://adamtheautomator.com/wp-content/uploads/2022/12/image-392.png)

Selecting an option from the message box

Based on your chosen option, the appropriate response is returned to the terminal like the one below.

![Verifying the returned response](https://adamtheautomator.com/wp-content/uploads/2022/12/image-393.png)

Verifying the returned response

## Conclusion

The skills in creating PowerShell message box come in handy with your PowerShell scripts, whether to make interactive tasks or notify users. And in this tutorial, you have discovered tools (Terminal.Gui, and Avalonia) to craft a modern PowerShell message box.

Why not get further acquainted with either of the tools you learned about in this tutorial?

With Terminal.Gui, try [adding extra elements like checkboxes and menus](https://blog.ironmansoftware.com/tui-powershell/#menus) to your message box. Or perhaps, visually design the message box with [Ironman Software’s Terminal GUI designer.](https://github.com/ironmansoftware/terminal-gui-designer) For Avalonia, you can play around with more controls, [such as textboxes, combo boxes, and calendars.](https://docs.avaloniaui.net/docs/controls)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-message-box%2F&text=How%20to%20Craft%20a%20Modern%20PowerShell%20Message%20Box)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-message-box%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-message-box%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
