Powershell – GUI – Create Message box with choices

You can incorporate message boxes into your scripts for an added level of fool proofing so that users have to make a choice before proceeding with the commands that follow.

Code description

  1. The messagebox will pop up with the text chosen
  2. A choice will be made by the user and be stored in $ButtonClicked
  3. If statements then cover what to do based on the choice made

Code

$ButtonClicked = [System.Windows.Forms.MessageBox]::Show("Do you wish to test this messagebox?", 'Warning', 'YesNo', 'Warning')

If ($ButtonClicked -eq 'Yes') {Write-Host "Yes was chosen."}
If ($ButtonClicked -eq 'No') {Write-Host "No was chosen."}

messagebox

messageboxyes

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s