PowerShell provides a powerful command-line interface to manage Windows systems. However, you can also create graphical user interfaces (GUIs) in PowerShell using the .NET framework. One useful GUI element you can add is a popup message box.
In this comprehensive guide, I‘ll cover how to create customized popup message boxes in PowerShell. You‘ll learn:
- How to configure PowerShell to use message boxes
- Creating a simple message box
- Customizing the title, buttons, icons and more
- Using message boxes to display warnings, errors and questions
- Best practices for using popup boxes effectively
Configuring PowerShell for Message Boxes
To use popup message boxes in PowerShell, you first need to import the System.Windows.Forms assembly. This provides access to the .NET classes for creating windows and dialogs:
Add-Type -AssemblyName System.Windows.Forms
If you fail to import this assembly, you‘ll get an error when trying to create a message box:
Exception calling "Show" with "1" argument(s): "Cannot find type
[System.Windows.Forms.MessageBox]: make sure the assembly containing this type is loaded."
So the Add-Type command is essential to configure the environment properly.
Creating a Simple PowerShell Message Box
Once the Windows Forms assembly is loaded, you can start using message boxes by calling the Show() static method on the System.Windows.Forms.MessageBox class:
[System.Windows.Forms.MessageBox]::Show("Welcome to PowerShell!")
This will pop up a simple message box with an OK button:

By default, the title bar says "Windows PowerShell" and there is an information icon displayed.
This is about the simplest message box you can create. But there are many ways to customize them further.
Customizing the Message Box Title
The title displayed in the message box title bar is the host application name by default. But you can override this by passing a string as the second parameter to Show():
[System.Windows.Forms.MessageBox]::Show("Welcome to PowerShell!", "Greeting")
Now "Greeting" is shown as the title:

This makes message boxes much clearer for users when you have multiple boxes open.
Changing Message Box Button Options
The default button displayed is OK, which closes the dialog. You can change this by passing a MessageBoxButtons enum value as the third parameter:
[System.Windows.Forms.MessageBox]::Show("Continue?", "Question", [System.Windows.Forms.MessageBoxButtons]::YesNo)
This will show Yes and No buttons instead:

Some common options include:
- OK – OK button only (default)
- OKCancel – OK and Cancel buttons
- YesNo – Yes and No buttons
- YesNoCancel – Yes, No and Cancel buttons
This gives you more flexibility to have users confirm actions or provide alternative choices.
Setting a Custom Message Box Icon
Another customization option is setting the icon displayed next to the message. This helps convey extra meaning to users.
You can specify one of the MessageBoxIcon enum values:
[System.Windows.Forms.MessageBox]::Show("Application not responding", "Warning", [System.Windows.Forms.MessageBoxButtons]::RetryCancel, [System.Windows.Forms.MessageBoxIcon]::Warning)
The different icon options include:
- None – No icon (default)
- Error – Red circle with X
- Hand – Pointing hand cursor
- Stop – Red octagon Stop Sign
- Question – Blue question mark
- Exclamation – Yellow exclamation in triangle
- Warning – Black exclamation in yellow triangle
- Asterisk – Asterisk symbol (*)
- Information – Blue circle with I
Here‘s an example with the Error icon:
![]()
So make use of these icons to visually communicate the nature of your message boxes.
Displaying Message Boxes as Warnings
A common scenario is to show warning message boxes to users. For example, before they take an action like deleting files or closing an application without saving.
You can configure a customized warning box like this:
$WarningTitle = "Delete Files"
$WarningMessage = "You are about to permanently delete these 5 files. Are you sure?"
$WarningButtons = [System.Windows.Forms.MessageBoxButtons]::YesNo
$WarningIcon = [System.Windows.Forms.MessageBoxIcon]::Warning
[System.Windows.Forms.MessageBox]::Show($WarningMessage, $WarningTitle, $WarningButtons, $WarningIcon)
Now the user sees an obvious warning before confirming the delete:

This pattern can be reused for all kinds of dangerous or destructive operations.
Displaying Errors in Message Boxes
Another scenario is displaying error messages when there is a problem for users. This might relate to system issues, missing resources, invalid inputs or unauthorized operations.
A customized error popup can be created like so:
$ErrorTitle = "File Error"
$ErrorMessage = "The settings.json file could not be saved. Check you have permissions to write to the folder."
[System.Windows.Forms.MessageBox]::Show($ErrorMessage, $ErrorTitle, [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error)
And will cleanly display error details to the user:

Having clear and explicit error message boxes improves the user experience of applications. They won‘t be left guessing what went wrong.
Asking Yes/No Questions in Message Boxes
You can also use message boxes to ask users questions. This is great for confirmation before continuing, e.g. "Are you sure you want to close without saving?"
A question message box can be shown by configuring like so:
$QuestionTitle = "Confirm Close"
$QuestionMessage = "You have unsaved changes. Are you sure you want to close?"
$QuestionButtons = [System.Windows.Forms.MessageBoxButtons]::YesNo
$QuestionIcon = [System.Windows.Forms.MessageBoxIcon]::Question
[System.Windows.Forms.MessageBox]::Show($QuestionMessage, $QuestionTitle, $QuestionButtons, $QuestionIcon)
The user is now presented with a clear confirmation question:

You can perform different logic depending on whether they choose Yes or No.
This approach avoids losing data or taking unintended actions.
Getting User Input from Message Boxes
As well as displaying information and questions, you can retrieve user input from message boxes.
The Show() method returns which button the user clicked. You need to store this result in a variable and check which enum value is returned:
$UserResponse = [System.Windows.Forms.MessageBox]::Show("What would you like to do?", "Choose an Option", [System.Windows.Forms.MessageBoxButtons]::YesNoCancel)
If ($UserResponse -eq [System.Windows.Forms.DialogResult]::Yes) {
# User chose Yes
}
ElseIf ($UserResponse -eq [System.Windows.Forms.DialogResult]::No) {
# User chose No
}
Else {
# User chose Cancel
}
Now your script can perform custom logic depending on exactly which option the user chose in the message box.
This enables scenarios like providing application settings or mode options through popup dialog choices.
Avoiding Overuse of Message Boxes
While message boxes seem very useful, you don‘t want to overdo it. Having too many popups appear will frustrate users.
Follow these best practices for using them effectively:
Use for Important Notifications – Only use popup boxes for essential user notifications, e.g. errors or warnings. Don‘t overuse them for general messages.
Provide Enough Details – Include clear, specific details about the issue and how to resolve it. Don‘t just have vague "Error!" type messages.
Limit Questions – Only ask question/confirmation boxes when truly necessary, not just for anything that continues execution flow.
Set Appropriate Icons – Match the icon displayed to the severity level of each message. Warning and error icons should represent real problems.
Allow Disabling – Provide a way to disable message boxes, e.g. with a parameter or config setting. Some users may not want to see them.
By following these principles, you‘ll have happy users who appreciate message boxes instead of being interrupted too frequently.
Summary
In this guide you learned how to leverage the flexibility of PowerShell and .NET to create customized popup message boxes.
Key points covered:
- Importing the System.Windows.Forms assembly to enable message boxes
- Displaying simple alerts with custom titles
- Changing the button options shown
- Setting icons to match error/warning/question contexts
- Configuring warning popups before dangerous operations
- Showing explicit error notices for issues
- Asking confirmation questions before continuing
- Retrieving and checking user input from message box choices
- Best practices for using popup boxes effectively
With these techniques, you can greatly enhance the user experience of PowerShell scripts and tools. Message boxes enable clear graphical communication according to the context.
Just be sure not to overuse them, instead reserving for important status notifications. Used judiciously, they are an invaluable UI component for prompting users.
So leverage message boxes to provide informative feedback as well as critical warnings and errors. Carefully crafted popups will aid adoption and usage of your PowerShell creations.


