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.
- Poll: How reliable are ChatGPT and Bing Chat? - Tue, May 23 2023
- Pip install Boto3 - Thu, Mar 24 2022
- Install Boto3 (AWS SDK for Python) in Visual Studio Code (VS Code) on Windows - Wed, Feb 23 2022
Token colors
To get an overview of your current color settings, you can use this command:
Get-PSReadlineOption | Select *color
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
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"
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!
To make your color changes permanent, you have to add the commands to one of your PowerShell profiles.
`Set-PSReadLineOption` has breaking changes. No more `-TokenKind` parameter.
@K.Kong
Why do you say that?
I have the latest official version of PSReadline, which is version 1.2, and the TokenKind parameter is still present.
I have PSReadLine 2.0 on PowerShell 6.2 and it’s not present
@Anonymous and @K.Kong
PSReadLine 2.0 is still a beta version and thus subject to changes until its General Availability.
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.
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
Reference:
https://www.powershellgallery.com/packages/PSReadLine/2.0.0-beta1/Content/Changes.txt
Moving forward, the -TOKENKIND parameter is gone. The advice in this article no longer applies to the latest versions of PowerShell 7.
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.
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.
Well whether they care or not is none of our concern. We still hate them with our guts.
In the upcoming world of 2022, I had to do this nonsense to set colors that work with a black Fluent Terminal background:
This has changed.
The correct commands can be found here:
https://docs.microsoft.com/en-us/powershell/module/PSReadline/Set-PSReadlineOption?view=powershell-5.1
I have used all these, many are most likely duplicate colors, but they all work
$Colors = @()
$Colors += “AliceBlue”
$Colors += “AntiqueWhite”
$Colors += “Aqua”
$Colors += “Aquamarine”
$Colors += “Azure”
$Colors += “Beige”
$Colors += “Bisque”
$Colors += “Black”
$Colors += “BlanchedAlmond”
$Colors += “Blue”
$Colors += “BlueViolet”
$Colors += “Brown”
$Colors += “BurlyWood”
$Colors += “CadetBlue”
$Colors += “Chartreuse”
$Colors += “Chocolate”
$Colors += “Coral”
$Colors += “CornflowerBlue”
$Colors += “Cornsilk”
$Colors += “Crimson”
$Colors += “Cyan”
$Colors += “DarkBlue”
$Colors += “DarkCyan”
$Colors += “DarkGoldenrod”
$Colors += “DarkGray”
$Colors += “DarkGreen”
$Colors += “DarkKhaki”
$Colors += “DarkMagenta”
$Colors += “DarkOliveGreen”
$Colors += “DarkOrange”
$Colors += “DarkOrchid”
$Colors += “DarkRed”
$Colors += “DarkSalmon”
$Colors += “DarkSeaGreen”
$Colors += “DarkSlateBlue”
$Colors += “DarkSlateGray”
$Colors += “DarkTurquoise”
$Colors += “DarkViolet”
$Colors += “DeepPink”
$Colors += “DeepSkyBlue”
$Colors += “DimGray”
$Colors += “DodgerBlue”
$Colors += “Firebrick”
$Colors += “FloralWhite”
$Colors += “ForestGreen”
$Colors += “Fuchsia”
$Colors += “Gainsboro”
$Colors += “GhostWhite”
$Colors += “Gold”
$Colors += “Goldenrod”
$Colors += “Gray”
$Colors += “Green”
$Colors += “GreenYellow”
$Colors += “Honeydew”
$Colors += “HotPink”
$Colors += “IndianRed”
$Colors += “Indigo”
$Colors += “Ivory”
$Colors += “Khaki”
$Colors += “Lavender”
$Colors += “LavenderBlush”
$Colors += “LawnGreen”
$Colors += “LemonChiffon”
$Colors += “LightBlue”
$Colors += “LightCoral”
$Colors += “LightCyan”
$Colors += “LightGoldenrodYellow”
$Colors += “LightGray”
$Colors += “LightGreen”
$Colors += “LightPink”
$Colors += “LightSalmon”
$Colors += “LightSeaGreen”
$Colors += “LightSkyBlue”
$Colors += “LightSlateGray”
$Colors += “LightSteelBlue”
$Colors += “LightYellow”
$Colors += “Lime”
$Colors += “LimeGreen”
$Colors += “Linen”
$Colors += “Magenta”
$Colors += “Maroon”
$Colors += “MediumAquamarine”
$Colors += “MediumBlue”
$Colors += “MediumOrchid”
$Colors += “MediumPurple”
$Colors += “MediumSeaGreen”
$Colors += “MediumSlateBlue”
$Colors += “MediumSpringGreen”
$Colors += “MediumTurquoise”
$Colors += “MediumVioletRed”
$Colors += “MidnightBlue”
$Colors += “MintCream”
$Colors += “MistyRose”
$Colors += “Moccasin”
$Colors += “NavajoWhite”
$Colors += “Navy”
$Colors += “OldLace”
$Colors += “Olive”
$Colors += “OliveDrab”
$Colors += “Orange”
$Colors += “OrangeRed”
$Colors += “Orchid”
$Colors += “PaleGoldenrod”
$Colors += “PaleGreen”
$Colors += “PaleTurquoise”
$Colors += “PaleVioletRed”
$Colors += “PapayaWhip”
$Colors += “PeachPuff”
$Colors += “Peru”
$Colors += “Pink”
$Colors += “Plum”
$Colors += “PowderBlue”
$Colors += “Purple”
$Colors += “Red”
$Colors += “RosyBrown”
$Colors += “RoyalBlue”
$Colors += “SaddleBrown”
$Colors += “Salmon”
$Colors += “SandyBrown”
$Colors += “SeaGreen”
$Colors += “SeaShell”
$Colors += “Sienna”
$Colors += “Silver”
$Colors += “SkyBlue”
$Colors += “SlateBlue”
$Colors += “SlateGray”
$Colors += “Snow”
$Colors += “SpringGreen”
$Colors += “SteelBlue”
$Colors += “Tan”
$Colors += “Teal”
$Colors += “Thistle”
$Colors += “Tomato”
$Colors += “Turquoise”
$Colors += “Violet”
$Colors += “Wheat”
$Colors += “White”
$Colors += “WhiteSmoke”
$Colors += “Yellow”
$Colors += “YellowGreen”
I have them in an array so I can add them to a dropdown box and change colors on the fly in some applications