How to turn off syntax highlighting in console? How to turn off syntax highlighting in console? powershell powershell

How to turn off syntax highlighting in console?


Syntax coloring in PowerShell v5 can be modified via Set-PSReadlineOption. The following command sets the foregound and background color for comments to the shell foreground and background color:

Set-PSReadlineOption -TokenKind Comment -ForegroundColor $Host.UI.RawUI.ForegroundColor -BackgroundColor $Host.UI.RawUI.BackgroundColor

or just black and white:

Set-PSReadlineOption -TokenKind Comment -ForegroundColor Black -BackgroundColor White

You need to do this for all TokenKind values to remove syntax coloring entirely.

If you also want to change output stream colors you can do that via the properties of the host's PrivateData object:

$Host.PrivateData.WarningForegroundColor = $Host.UI.RawUI.ForegroundColor$Host.PrivateData.WarningBackgroundColor = $Host.UI.RawUI.BackgroundColor...

Put all of these statements into your profile to get them applied every time you start PowerShell, e.g.:

$HOME\Documents\WindowsPowerShell\profile.ps1


Example, how to turn off all syntax highlighting:

Set-PSReadlineOption -TokenKind Parameter -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind String -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Operator -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Type -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Variable -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Number -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Member -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Command -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Comment -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -TokenKind Keyword -ForegroundColor DarkYellow -BackgroundColor DarkMagentaSet-PSReadlineOption -ContinuationPromptForegroundColor DarkYellow -ContinuationPromptBackgroundColor DarkMagentaSet-PSReadlineOption -EmphasisForegroundColor DarkYellow -EmphasisBackgroundColor DarkMagentaSet-PSReadlineOption -ErrorForegroundColor DarkYellow -ErrorBackgroundColor DarkMagenta(Get-Host).PrivateData.ErrorForegroundColor="DarkYellow"(Get-Host).PrivateData.ErrorBackgroundColor="DarkMagenta"(Get-Host).PrivateData.WarningForegroundColor="DarkYellow"(Get-Host).PrivateData.WarningBackgroundColor="DarkMagenta"(Get-Host).PrivateData.DebugForegroundColor="DarkYellow"(Get-Host).PrivateData.DebugBackgroundColor="DarkMagenta"(Get-Host).PrivateData.VerboseForegroundColor="DarkYellow"(Get-Host).PrivateData.VerboseBackgroundColor="DarkMagenta"(Get-Host).PrivateData.ProgressForegroundColor="DarkYellow"(Get-Host).PrivateData.ProgressBackgroundColor="DarkMagenta"

See screenshot (Windows10)


The syntax changed in a recent update. The old syntax will now give you a pesky error message:

Set-PSReadLineOption : A positional parameter cannot be found that accepts argument 'Command'.                                                             At line:1 char:1                                                                + Set-PSReadLineOption 'Command' white black                                    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                        + CategoryInfo          : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption                      

or

Set-PSReadLineOption : A parameter cannot be found that matches parameter name  'TokenKind'.At line:1 char:22+ Set-PSReadlineOption -TokenKind Comment -ForegroundColor 'black' -Bac ...+                      ~~~~~~~~~~    + CategoryInfo          : InvalidArgument: (:) [Set-PSReadLineOption], Par ameterBindingException    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetP SReadLineOption                                 

The updated syntax seems to require you to pass in a dictionary of new settings.

Set-PSReadLineOption -Colors @{None='black';Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}

If you get

Set-PSReadLineOption: 'None' is not a valid color property

(which apparently means you are on Linux), take out the None='black';, like this:

Set-PSReadLineOption -Colors @{Comment='black';Keyword='black';String='black';Operator='black';Variable='black';Command='black';Parameter='black';Type='black';Number='black';Member='black'}    

See also https://github.com/PowerShell/PSReadLine/issues/738