18

I just want PowerShell to be black text on a white background. However, PowerShell v5 highlights my commands and makes them yellow, which is impossible to see. Is there a way to turn off ALL syntax highlighting in PowerShell?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Simonxca
  • 648
  • 1
  • 6
  • 18

6 Answers6

10

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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • I must say I like the new syntax coloring, but this answer is also useful for customizing it to your individual preferences. – marsze Jul 26 '16 at 09:33
  • I fall into situation when I need to display a PS code examples on the projector and projector has an issue - it almost doesn't display a red color. So reading the default color scheme becomes almost impossible. With this, I reconfigured the color scheme to black and white and that help! Thanks ) – Vladimir Dronov Mar 22 '17 at 06:52
  • 3
    Thanks for this and all of the other answers. It is just nuts that PS doesn't provide an easier way to simply turn off syntax highlighting and use the window's default colors for text and background. – Jamie Hanrahan Dec 22 '18 at 23:06
7

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

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • Set-PSReadLineOption: 'None' is not a valid color property ? – Gerard H. Pille Feb 03 '21 at 11:56
  • @GerardH.Pille I guess it changed again? Fortunately, I no longer have a Windows environment where I can troubleshoot that. Try taking out the `None='black';` from inside the `@{...}` – tripleee Feb 03 '21 at 13:07
  • That's what I did. But perhaps I should have added that I'm trying this with Powershell on Linux. – Gerard H. Pille Feb 03 '21 at 13:14
  • I didn't understand from your comment that that fixed it, but I have worked it out and added an update. Thanks for prodding me, but perhaps work on providing more context in your comments. At your reputation level, I believe you should be eligible to submit an edit suggestion to improve this answer, too. – tripleee Feb 03 '21 at 13:38
  • In case others need it going forward, `docker pull mcr.microsoft.com/powershell:latest` gets you a Debian image with Powershell. Installing it yourself in a Docker image is problematic because the various installation scripts I could find require `systemd` which you don't get out of the box with stock Docker images for Debian. The source for this image is https://github.com/PowerShell/PowerShell-Docker – tripleee Feb 03 '21 at 13:40
7

https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-7.1#example-4--set-multiple-color-options

Set-PSReadLineOption -Colors @{
  Command            = 'White'
  Number             = 'White'
  Member             = 'White'
  Operator           = 'White'
  Type               = 'White'
  Variable           = 'White'
  Parameter          = 'White'
  ContinuationPrompt = 'White'
  Default            = 'White'
}
austinheiman
  • 939
  • 1
  • 12
  • 17
5

Example, how to turn off all syntax highlighting:

Set-PSReadlineOption -TokenKind Parameter -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind String -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Operator -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Type -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Variable -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Number -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Member -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Command -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Comment -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -TokenKind Keyword -ForegroundColor DarkYellow -BackgroundColor DarkMagenta
Set-PSReadlineOption -ContinuationPromptForegroundColor DarkYellow -ContinuationPromptBackgroundColor DarkMagenta
Set-PSReadlineOption -EmphasisForegroundColor DarkYellow -EmphasisBackgroundColor DarkMagenta
Set-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)

benek2048
  • 51
  • 1
  • 2
1
get-help set-psreadlineoption

https://learn.microsoft.com/en-us/powershell/module/PSReadline/Set-PSReadlineOption

'None', 'Comment', 'Keyword', 'String', 'Operator', 
'Variable', 'Command', 'Parameter', 'Type', 'Number', 'Member' |
foreach { set-psreadlineoption $_  black white }
MarcH
  • 18,738
  • 1
  • 30
  • 25
0

Here's how I'm doing it in osx for the things that immediately bother me:

$a = get-psreadlineoption | select ErrorBackgroundColor
$clear = $a.ErrorBackgroundColor

'command','number','operator','member' |
foreach { set-psreadlineoption $_ black $clear }
js2010
  • 23,033
  • 6
  • 64
  • 66