I know you can do something like this on PowerShell Version 5 (Shown Below) but is there any way to reproduce a popup message box that works on both Windows and Mac OS platforms?
$ButtonType = [System.Windows.Forms.MessageBoxButtons]::OK
$MessageIcon = [System.Windows.Forms.MessageBoxIcon]::Information
$MessageBody = "Message Body goes here"
$MessageTitle = "Title"
$Result = [System.Windows.Forms.MessageBox]::Show($MessageBody,$MessageTitle,$ButtonType,$MessageIcon)
Output of Code above
Best Answer
The
Show-MessageBox
function defined below offers message-box functionality on both Windows and macOS, modeled on the WinFormsMessageBox
class.Examples:
The syntax (spread across multiple lines for readability):
Note:
On macOS, AppleScript's
display alert
command is used to create the message box.informational
,warning
, andcritical
, the former two show the same icon - a folder - and the latter overlays the folder icon only with an exclamation mark.For cross-platform consistency the output value is a string, namely the name of the button pressed by the user.
-DefaultButtonIndex
is the0
-based index of the button that will be pressed when the user just presses Enter.Cancel
button is present, Esc presses it.No
,Abort
orCancel
button is present and it isn't the default button, Esc presses it.Show-MessageBox
source code: