Have you ever grown tired of looking at the different colors of the PowerShell console? Have you ever thought to change your PowerShell console colors? I have dabbled and changed them up a bit myself, but there some things to keep in mind.
At the 2017 PowerShell and DevOPs Summit earlier this year Don Jones (PowerShell MVP) brought up some good points that red error messages are difficult to read and can have negative connotations. Red ink on test scores, anyone?
Whatever the case, let’s change ’em up!
Get-Host and $Host
In order to change the colors, I’ll familiarize myself with where that info is stored.
This info is stored in the variable $host or by using the Get-Host cmdlet. These commands retrieve an object that has info about the PowerShell console itself, the console host.
Let’s see what both of those look like.
Fancy. Lots of fancy going on here.
Change the PowerShell colors
There are a lot of properties that I can dive into with the $host object, but I’m going to dive into the PrivateData property today. It has all the color goodies that I’m looking for.
This is where the colors are set for the Errors, Warnings, Debug, Verbose, and Progress streams.
Jackpot! Let’s change the error colors for fun! I’m going to take a wild guess that White is a valid color.
Yikes! That’s even more harsh on my eyes! Don’t stare too long!
What else can I change it to? I might be tempted to just plug in values until I get lucky, but there’s a better way. After all, it’s PowerShell we’re talking about!
First, I’ll find out what type of object the ErrorBackgroundColor is. Then, I should be able to figure out what to do with it.
It looks like we’re working with an enum called ConsoleColor. Googling this would probably lead me to find the MSDN page, but I want to be cool and use PowerShell to list the enum values.
Let’s go back to the error background that we set as white and change it to the background of the window – DarkMagenta.
Taking this a step further, we’ll even change the error foreground color to make it much more soothing to the eyes.
Much better! Now I don’t feel like PowerShell is shouting at me when errors occur. Sometimes I’ll switch it up between DarkGray, DarkGreen, and even DarkCyan!
I like to live on the edge.
Change the console window colors
Changing the main console foreground and background is slightly different. That data is stored in a separate location – $host.UI.RawUI
Let’s change it!
That worked! …kind of. One interesting thing to note is that it doesn’t seem to completely refresh until you close and reopen your PowerShell window or until you clear the screen.
Congratulations! You now have control over the colors of your PowerShell console! Woo!
Also, as a side note – you can extend this fancy colorization to the ISE. But, I think I’ll save that for another day.
Kris was an employee at PDQ.