Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET Coming Soon: GET:IT Endpoint Management 1-Day Conference on September 28th at 9:30 AM ET
PowerShell

PowerShell Problem Solver: Make it Pretty

During Microsoft Ignite, I took part in a community panel discussion on PowerShell. Well, not so much a discussion as questions and answers. One of the questions, which I get from time to time, concerned how to change the color of error messages in the PowerShell console. It is actually quite easy, and once you know the “trick”, it opens up a lot of possibilities. Before I get into it, understand that everything I am going to demonstrate is for the PowerShell console, not the PowerShell ISE. While some things might work in the ISE, it has its own settings for customizing the appearance. Perhaps I’ll cover that in another article.

In the console, this is the normal situation.

So instead of red text on a black background, you want something else. The settings are found in $host.privatedata.

Sponsored Content

Say Goodbye to Traditional PC Lifecycle Management

Traditional IT tools, including Microsoft SCCM, Ghost Solution Suite, and KACE, often require considerable custom configurations by T3 technicians (an expensive and often elusive IT resource) to enable management of a hybrid onsite + remote workforce. In many cases, even with the best resources, organizations are finding that these on-premise tools simply cannot support remote endpoints consistently and reliably due to infrastructure limitations.

The color settings are the same you would use with Write-Host. You can use the .NET framework to enumerate these values if you don’t remember them all.

To change, all you need to do is assign a new value:

 

Perhaps this is more appealing.

This change only lasts for the duration of your PowerShell session so if you don’t like it, you’ll get the defaults the next time you start PowerShell. But if it is something you want to keep, put the commands in your PowerShell profile script. If you want to change other color schemes for the Verbose or Warning streams, feel free to experiment. By the way, if you want to change the console foreground and/or background color, those values are found in $host.ui.rawui.

Of if you are feeling .NET-inclined you can use the [console] class.

Although as you can see, DarkYellow isn’t really yellow. But It is easy enough to change.

 

You will want to run Clear-Host after making changes like this.

Again, if you want this to be a persistent change, put the commands in your profile. There’s a good chance Windows will remember your preference, but it doesn’t hurt to configure in your profile.

So given, all of this, I wrote a few functions you can use to manage your color schemes. First, is a quick function to list the color names.

GET-CONSOLESCOLOR

I even added a parameter to display the values in the corresponding color.

Obviously you can’t see the color name use by the background, so I added a popup. In a similar fashion I wrote this function to show you current settings.

Show-ConsoleColor

As you experiment finding the right values, it made sense to me to include a test function.

TEST-CONSOLESCOLOR

Once you have the shell colorized the way you want it, I thought it might be nice to be able to export the values.

EXPORT-COLOR

The function will export your current color scheme to a CSV file.

 

Naturally, you need to be able to import the color settings.

IMPORT-CONSOLECOLOR

With these functions, if you were so inclined you could create console themes. Here’s one.

PSBRIGHT

Changing schemes is as simple as importing the CSV file.

 

That will wake you up! Or you can try my PSDark theme.

PSDARK.CSV

If you come up with some nice color schemes, I hope you’ll share them. In the meantime I’m sure I’ve given you enough PowerShell toys to have a little fun with. I hope you enjoy.

Related Topics:

BECOME A PETRI MEMBER:

Don't have a login but want to join the conversation? Sign up for a Petri Account

Register
Comments (0)

Leave a Reply