How to set colors in PSReadLine in PowerShell

There are a couple different ways. You can do this:

Set-PSReadlineOption -TokenKind Comment -ForegroundColor Green

Alternatively:

$options = Get-PSReadlineOption
$options.CommentForegroundColor = Green

The possible colors are from the .NET ConsoleColor Enumeration. The actual RGB color values can be changed in the console properties dialog.

To see the current color settings, execute Get-PSReadlineOption by itself.


While the methods that Jason Shirk describes still work on my Mac that has PowerShell Core version 6.0.1, as documented here, they no longer work on my Linux machine, which is on version 6.1.0.

It seems that they completely changed the interface of this cmdlet: PowerShell 6 Set-PSReadlineOption.

Now, you can supply a hash table of colors as the value to the -Colors parameter. The good thing is that you now have many more color options.

From the examples:

$colors = @{
  # ConsoleColor enum has all the old colors
  "Error" = [ConsoleColor]::DarkRed

  # A mustardy 24 bit color escape sequence
  "String" = "$([char]0x1b)[38;5;100m"

  # A light slate blue RGB value
  "Command" = "#8470FF"
}

Set-PSReadLineOption -Colors $colors

Tags:

Powershell