PowerShell’s Docs General Docs Change PowerShell console syntax highlighting colors of PSReadLine

You can change the PowerShell console colors of the PSReadLine module that Microsoft delivers with PowerShell since version 5. We have to distinguish between colors for tokens of a certain type (for examples cmdlets or strings) and the colors of console itself.

Latest posts by Michael Pietroforte (see all)

Token colors ^

To get an overview of your current color settings, you can use this command:

Get-PSReadlineOption | Select *color
Displaying the PowerShell console color settings

Displaying the PowerShell console color settings

To change the colors, you can use the Set-PSReadlineOption cmdlet. However, you can't just use the parameters you see in the above screenshot. This is the syntax of the cmdlet:

Set-PSReadlineOption

[-TokenKind] <TokenClassification>

[[-ForegroundColor] <ConsoleColor>]

[[-BackgroundColor] <ConsoleColor>]

The TokenKind parameter specifies the type of item for which you can change the color. Say you want to change the color of the variables; then TokenKind Variable. Or if you want to change color of the cmdlets, the TokenKind is Command. The latter corresponds to CommandForegroundColor in the screenshot above. These are the supported TokenKind parameters: None, Comment, Keyword, String, Operator, Variable, Command, Parameter, Type, Number, and Member.

For instance, if you want to change the CommandForegroundColor to white, you need this command:

Set-PSReadlineOption -TokenKind Command -ForegroundColor White
Changing the command foreground color

Changing the command foreground color

If you want to reset all token colors to the default configuration, then this command helps:

Set-PSReadlineOption -ResetTokenColors

Console colors ^

You can change the general background colors through the $host.ui.rawui object and the colors for errors and warnings through the $Host.PrivateData object.

For instance, to change the general background color of the console to black, you can use this command:

$host.ui.rawui.BackgroundColor = "Black"

And if you want to replace the red PowerShell error messages, these commands do the trick:

$Host.PrivateData.ErrorBackgroundColor = "Blue"
$Host.PrivateData.ErrorForegroundColor = "White"
Changing the colors of error messages

Changing the colors of error messages

Here is the complete list:

$host.ui.rawui.ForegroundColor = <ConsoleColor>
$host.ui.rawui.BackgroundColor = <ConsoleColor>
$Host.PrivateData.ErrorForegroundColor = <ConsoleColor>
$Host.PrivateData.ErrorBackgroundColor = <ConsoleColor>
$Host.PrivateData.WarningForegroundColor = <ConsoleColor>
$Host.PrivateData.WarningBackgroundColor = <ConsoleColor>
$Host.PrivateData.DebugForegroundColor = <ConsoleColor>
$Host.PrivateData.DebugBackgroundColor = <ConsoleColor>
$Host.PrivateData.VerboseForegroundColor = <ConsoleColor>
$Host.PrivateData.VerboseBackgroundColor = <ConsoleColor>
$Host.PrivateData.ProgressForegroundColor = <ConsoleColor>
$Host.PrivateData.ProgressBackgroundColor = <ConsoleColor>

Available colors ^

As mentioned above, the number of colors you can choose from is somewhat limited: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, and White.

To see how the colors look you can install the TMOutput module:

Install-Module -Name TMOutput

You can the display the colors with the Show-TMOutputColor cmdlet:

Subscribe to 4sysops newsletter!

Displaying available PSReadLine colors

Displaying available PSReadLine colors

To make your color changes permanent, you have to add the commands to one of your PowerShell profiles.

+3

Discussion (10)

  1. I tried with the the current version installed with Windows 1903 and the help file mentions TokenKind but it doesn't recognize the paramater.  I had to do Set-PSReadlineOption -Colors @{Command = "Blue"} as an example.

    +3

  2. Moving forward, the -TOKENKIND parameter is gone. The advice in this article no longer applies to the latest versions of PowerShell 7. 

    0

  3. There are no words to describe how much I hate what Microsoft did here.  I am working on a VM, it is past midnight and the standard color scheme is very difficult to read.  For some ridiculous trendy reason, the background on PowerShell is black.  I went in and changed the text to black and the background to white.  i did this in Default and Properties.  Well, because of the syntax highlighting, my color changes did not do what I think any reasonable person would expect.  The background did become white, but the text was yellow and it was even harder to read. 

    I found you very informative article and surprise, surprise, Microsoft provides a great deal of customizability, but not through their GUI.  It is very hard to type the commands when I can't read what I am typing.  There should be a light mode and a dark mode and then if someone wants to go to the trouble to change specific aspects of the syntax to their favorite color, then they can type in all the commands.  

    So, thank you for helping me find out what Microsoft couldn't bother to tell me.  Microsoft, if you are listening, it is stupid things like this that make people hate your environment.  

    +12

    • In the upcoming new world, it will be less relevant whether people hate a vendor for such things, because they typically don't care -- instead, they will be financially liable for the wasted time users encounter when standard instructions no longer work.

      0

Leave a Reply

Please enclose code in pre tags

Your email address will not be published. Required fields are marked *

© 4sysops 2006 - 2021

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account