Categories Articles

PowerShell function to standardize message box script outputs

I always try to save time and keep consistency as much as I can on my daily tasks. I was thinking about that when writing a script to one of my customers and I had to deal with outputs as part of the process, so I thought that would be a good time to create a consistent function. The first visual language that I learned when I was a teenager was Visual Basic 3.0 and, of course, the coolest function that I fell in love was the msgbox, which created all those cool message boxes for me in a single line. Since I won’t be able to deliver the same graphical user experience in PowerShell that I had back in the day with Visual Basic, my decision was to use a similar interface from Linux (to remind me of the good old times with Red Hat).

The idea behind this PowerShell function below is to provide a simpler but similar experience. You just need to provide the caption, message, type (0 is good, 1 is warning and 2 is an error). I’m asking $MaxSize. Basically, I want to know how large your message throughout your script will be. If you know, then I can provide all the status aligned in the output by adding spaces between the message and the status icon. If I don’t know the value, I’m guessing 66 (big fan of “The Prisoner”!)

Keep in mind that we can use variables when passing parameters to the function. In the first example below, it will save some time to write into the code.

The PowerShell function can be found at my GitHub here.

Featured image: Shutterstock / TechGenix photo illustration

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides of the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange, CISSP and several other certifications. Anderson contributes to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at,, and Anderson (Portuguese).

Published by
Anderson Patricio

Recent Posts

Intel and MediaTek announce 5G modem solutions partnership

A new partnership between Intel and MediaTek to develop 5G modem solutions wants to be in the fast lane when…

5 hours ago

Azure Quick Tip: Troubleshooting your code with test pane

Sometimes, it’s the simple things that can save you a lot of headaches. As this Quick Tip shows, always make…

7 hours ago

Creating bootable ISO files for Windows 10 the easy way

Microsoft has simplified the process of creating bootable ISO files, and we show you the easiest ways to create them…

9 hours ago

Review: Office 365 management solutions CoreLearning and CoreAdoption

CoreLearning and CoreAdoption are powerful solutions to drive end-user adoption of Office 365 applications, services, and features. Here’s our review.

12 hours ago

Windows 7, TrueCrypt and KB4530734 - Configuring Windows Boot Loop

In case you are using Windows 7 with System Disk encrypted by TrueCrypt(Possibly VeraCrypt is affected as well) and boot…

21 hours ago

Moving Azure resources: Pay attention to the details!

Here’s a simple but efficient way to move your Azure resources. This quick tutorial will show you how to do…

1 day ago