Powershell and the Message box

We have all seen the message boxes pop up when we are working with forms, online applications, software installs, etc. Today I am going to go through the different types of message boxes available within PowerShell. There are a number of elements that we can use to get the best functionality from our message box.

First things first, we need to load in the Powershell Assembly:

We can get the message box to display any type of message we want, using static text or even have it show a variable or part of string.

Here is the Powershell code to create a simple message box:


Sample Message Box
Sample Message Box – No title


As we can see from the message box above we have our message displaying in section 2 and an OK button in section 3. While this is a pretty basic message box it is quite useful when you want the end user to stop and think about what they might be doing. Section 1 is empty.


Next I would like to add a title for my message box, something to fill in section 1. By adding more to the above code we can define the title of the message box.

Message Box - With Title
Message Box – With Title


Now we move on to the different types of message boxes. As I said earlier, there are 6 types. The type numbers we use range from 0 to 5. If we don’t use a type number the default is 0.


Type 0: Standard message box with just the OK button.


Type 1: OK and Cancel button message box.

Type 2: Abort, Retry, Ignore message box

Type 3: Yes, No, Cancel button message box.

Type 4: Yes, No button message box.

And finally, Type 5: Retry, Cancel button message box.

All of the above message box types will return the value of the button selected. You can use this information to decide what happens next in your script.

As always, please feel free to comment.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.