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.

Michael Pietroforte

Michael Pietroforte is the founder and editor in chief of 4sysops. He has more than 35 years of experience in IT management and system administration.

Token colors ^

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

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:

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:

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:

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:

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

Changing the colors of error messages

Changing the colors of error messages

Here is the complete list:

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:

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

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.

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!


Discussion (8)

  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.


  2. PSReadLine 2.0.0-beta1 has this breaking change.

    Breaking changes:
    * Set-PSReadLineOption options have changed
      - To specify colors, use the new `-Color` parameter and pass a Hashtable


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


Leave a Reply

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

© 4sysops 2006 - 2019


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


Log in with your credentials


Forgot your details?

Create Account