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 Techgenix.com, MSExchange.org, ITPROCentral.com and Anderson Patricio.org (Portuguese).

Share
Published by
Anderson Patricio

Recent Posts

RAID 1 vs. RAID 5: When to use each level and why

Redundant array of independent disks (RAID) is the logical grouping of two or more disks…

16 hours ago

Microsoft 365 adds online scheduling to Microsoft Bookings app

Microsoft 365 users have access to an app called Microsoft Bookings. Before you dismiss it…

21 hours ago

Biometrics authentication: Where the technology is now — and where it’s going

As cyberthreats rise in number and complexity, biometrics authentication technology has seen rapid adoption and…

4 days ago

Remote work vulnerabilities: Tips on avoiding a nightmare scenario

Remote work is likely to remain permanent — and so will the vulnerabilities it brings…

4 days ago

Microsoft Teams rolls out new video meetings features

Microsoft Teams is adding new features to help employees adjust to the new normal of…

5 days ago

Azure Charts: If you’re not using this cool feature, you should be

This Azure Quick Tip shows you how to use Azure Charts, a great resource that…

5 days ago