Tag Archives: Write-Host

Friday Fun Send a Colorful Message

Next week is Pluralsight’s 10th anniversary. In preparing for that happy event, I wanted to send a special greeting. Of course, because my courses are on PowerShell it only seemed appropriate to use PowerShell to display my message. In fact, let’s jump right to the result.


Here’s how I did it.

The script takes a string, in this case a here string stored as $msg, and writes each character to the console using Write-Host. I’m using Write-Host so that I can take advantage of foreground and background colors. I get a random color for each from a list of possible console colors, skipping the color used for the current console background. My script uses a Do loop to get a random color for the background that is different than what is chosen for the foreground. I only use a color scheme if there is a non-space character. I suppose I could have turned things around and tested with -match against \S.

Anyway, a short and simple script that gets the message across in a colorful way. Enjoy and have a great weekend.

Another PowerShell Valentine

I’ve been sharing some Valentine’s Day themed fun on Twitter today. This one is a bit too long to fit into a tweet.

To get the full effect you need to run in the console and not the ISE. It works in the ISE but you won’t get the “special” characters.

Updated Console Graphing in PowerShell

The other day Distinguished Engineer and PowerShell Godfather Jeffrey Snover posted a blog article about the evils of Write-Host. His take, which many agree with, is that Write-Host is a special case cmdlet. In his article he mentions console graphing as an example. I wrote such a script earlier this year. Mr. Snover’s post drove some new attention to my post and I realized it needed a little polishing.

Here is a revised version of that script.

I didn’t make too many structural changes other than to add Set-StrictMode and revise some of my IF statements to test for ParameterSetName instead of a variable. Using StrictMode, which is a good thing, caused problems in my earlier version. I also went through and added some new examples, including a few PowerShell 4.0.

The function still requires at least PowerShell 3.0. But it allows you to do something like this:


All you can do is look at this but sometimes, that’s all you need.