Here’s some very simple and straight-forward code to display a custom MsgBox in PowerShell.
You can specify message text, header, default buttons, and icon to display. Your code can then respond to the result with a condition.
The Add-Type statement loads the .NET assemblies required to display the message box. This statement is necessary only in a console window because a console PowerShell does not load graphical assemblies. Inside the ISE editor, you could get away with skipping Add-Type, just because the type System.Windows.Forms is loaded by the ISE editor by default.
|# add the required .NET assembly:
Add-Type -AssemblyName System.Windows.Forms
# show the MsgBox:
# check the result:
Displaying a MsgBox and looking at the results
When you call Show() with an invalid parameter (such as “Maybe” instead of “YesNo”), the red error message will list the legal values you can use.