How to Change PowerShell Console Font and Background Colors

Posted on May 27, 2015 by Jeff Hicks in PowerShell with 0 Comments

During Microsoft Ignite, I took part in a community panel discussion on PowerShell. One of the questions I received is concerned with how to change the color of error messages in the PowerShell console. It is actually quite easy, and it opens up a lot of possibilities once you know the trick. Before I get into how to do this, let’s understand that everything I am going to demonstrate is for the PowerShell console, not the PowerShell ISE. Although some things might work in the ISE, it has its own settings for customizing the appearance, which I might cover in another article.

In the console, this is the normal situation.

Default error message color in the Windows PowerShell console. (Image Credit: Jeff Hicks)

Default error message color in the Windows PowerShell console. (Image Credit: Jeff Hicks)

You might want a different color instead of the default red text on black background. The settings are found in $host.privatedata.

$host.PrivateData settings. (Image Credit: Jeff Hicks)

$host.PrivateData settings. (Image Credit: Jeff Hicks)

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

Enumerating values with the .NET Framework in Windows PowerShell. (Image Credit: Jeff Hicks)

Enumerating values with the .NET Framework in Windows PowerShell. (Image Credit: Jeff Hicks)

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

The result might be more appealing:

The result of our color modification for the PowerShell console. (Image Credit: Jeff Hicks)

The result of our color modification for the PowerShell console. (Image Credit: Jeff Hicks)

Note that this change only lasts for the duration of your PowerShell session. If you don’t like your new color settings, then you’ll revert to the default settings the next time you start PowerShell. If this is something you want to keep, you can easily put the commands in your PowerShell profile script to run automatically for each new PowerShell session.

Sponsored

If you want to change other color schemes for the Verbose or Warning streams, then feel free to experiment. If you want to change the console foreground or background color, then those values are found in $host.ui.rawui.

Foreground and background colors are found in the $host.ui.RawUI property. (Image Credit: Jeff Hicks)

Foreground and background colors are found in the $host.ui.RawUI property. (Image Credit: Jeff Hicks)

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

The console class also lets you change the foreground or background color. (Image Credit: Jeff Hicks)

The console class also lets you change the foreground or background color. (Image Credit: Jeff Hicks)

As you can see, DarkYellow isn’t really yellow, but that’s easy to change.

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

Our new foreground and background colors in the PowerShell console. (Image Credit: Jeff Hicks)

Our new foreground and background colors in the PowerShell console. (Image Credit: Jeff Hicks)

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

I have also wrote a few functions that you can use to manage your color schemes. The first function is a quick function to list the color names.

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

Using get-consolecolor in Windows PowerShell. (Image Credit: Jeff Hicks)

Using get-consolecolor in Windows PowerShell. (Image Credit: Jeff Hicks)

Obviously you can’t see the color name used by the background, so I added a popup instead. In a similar fashionm I wrote this function to display current settings.

Using show-consolecolor in Windows PowerShell. (Image Credit: Jeff Hicks)

Using show-consolecolor in Windows PowerShell. (Image Credit: Jeff Hicks)

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

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

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

Sponsored

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

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

Changing schemes is as simple as importing the CSV file.

Importing a CSV file to change the PowerShell console's colors. (Image Credit: Jeff Hicks)

Importing a CSV file to change the PowerShell console’s colors. (Image Credit: Jeff Hicks)

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

A darker theme for the PowerShell console. (Image Credit: Jeff Hicks)

A darker theme for the PowerShell console. (Image Credit: Jeff Hicks)

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. I hope you enjoy.

Sponsored

Tagged with , ,