Create MessageBox easily with PowerShell

Hello,

Hereunder a nice way to create simple messagebox with PowerShell :

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[System.Windows.Forms.Application]::EnableVisualStyles()
[System.Windows.Forms.MessageBox]::Show("Would you like a MessageBox popup ?","This is a question !", "YesNoCancel”

QuestionMessageBox

This uses a .Net method :

MessageBox.Show

You can do a lot of different kinds of messagebox :

[System.Windows.Forms.MessageBox]::Show("Would you like a MessageBox popup ?","This is a warning !", "AbortRetryIgnore” , "Warning”)

WarningMessageBox

[System.Windows.Forms.MessageBox]::Show("Would you like a MessageBox popup ?","This is an error !", "Ok” , "Error”)

ErrorMessageBox

When you click on a button, the button value is returned to PowerShell, so, you can take different action depending of the clicked button :

WarningMessageBoxReturnedClick

You can list the possible windows types and the possible buttons with those enum :

[Enum]::GetNames([System.Windows.Forms.MessageBoxIcon])
[Enum]::GetNames([System.Windows.Forms.MessageBoxButtons])

PossibleWindowsTypesAnButtons

One thought on “Create MessageBox easily with PowerShell

  1. Pingback: Create Input Box PowerShell - It for DummiesIt for Dummies

Leave a Reply