$Answer = [Windows.Forms.MessageBox]::Show("DJIA has dropped by 300 points today `n Do you want to `n go to your IRA?", "Trade Alert",
If ($Answer -eq "Yes")
Write-Host "Do Something."
Line 2 Saves the answer of our message box in a the variable $Answer. To control the type of message box that we display, we have several options.
The Windows.Forms.MessageBox class is overloaded. That means that you can implement it in several different ways. In this instance, we are using the Show method. Take a look at the screen shot below of the many different versions of the Show method for this class:
Clicking on this item, we are taken to the MessageBox.Show Method (String, String, MessageBoxButtons, MessageBoxIcon) method on MSDN. Here we can see that the first string is the message and the second is the caption on the message box window.
From here, if we click on System.Windows.Forms.MessageBoxButtons, we can see the types of buttons that we have access to.
In this example, we are using YesNo. Yes or No will be returned and stored in $Answer
We are also choosing an icon for this message box from MessageBoxIcon. Here are valid options are:
In the end, this is what you will see:
Either the string Yes or No will be returned when the appropriate button is clicked.