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.
- Author and member of the year 2019 – Why DevOps still doesn't rule the IT world - Wed, Jan 1 2020
- Results of the 4sysops member and author competition in 2018 - Tue, Jan 8 2019
- Why Microsoft is using Windows customers as guinea pigs - Reply to Tim Warner - Tue, Dec 18 2018
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:
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:
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:
To make your color changes permanent, you have to add the commands to one of your PowerShell profiles.