Share via


How do I change the text colors in a PowerShell command window?

Question

Tuesday, October 6, 2015 6:17 PM | 2 votes

When running PowerShell in an elevated command prompt, Win 10's PoSH seems to want to color different words with different colors a la ISE.  Anyway, most of the colors are readable, but some are bit too dark to stand out, and nothing in $host.ui.rawui seems to change them.  Can someone point me to where it gets the idea to make some text yellow, green, white, etc?

Thanks.

All replies (10)

Monday, October 12, 2015 7:18 PM âś…Answered | 5 votes

This isn't the whole answer, but putting these lines into your powershell profile (a file named profile.ps1 which sits in your Documents\WindowsPowerShell\ folder (you may have to create that folder) will remove most of the unreadable colors:

Set-PSReadlineOption -TokenKind comment -ForegroundColor white
Set-PSReadlineOption -TokenKind none -ForegroundColor white
Set-PSReadlineOption -TokenKind command -ForegroundColor white
Set-PSReadlineOption -TokenKind parameter -ForegroundColor white
Set-PSReadlineOption -TokenKind variable -ForegroundColor white
Set-PSReadlineOption -TokenKind type -ForegroundColor white
Set-PSReadlineOption -TokenKind number -ForegroundColor white
Set-PSReadlineOption -TokenKind string -ForegroundColor white
Set-PSReadlineOption -TokenKind operator -ForegroundColor white
Set-PSReadlineOption -TokenKind member -ForegroundColor white

And if you have never done it before, you'll need just once to type this  in PowerShell:

Set-ExecutionPolicy RemoteSigned


Tuesday, October 6, 2015 8:59 PM | 1 vote

Hmm interesting, can change background colour with $host.ui.rawui or the properties of the prompt but neither change the colour of the commands.

If I mention opening PowerShell ISE as admin by right click and selecting Run as admin does that help \ bypass the issue?

Other than that perhaps post in the

https://social.technet.microsoft.com/Forums/en-US/home?forum=winserverpowershell

forum as many PowerShell gurus frequent that forum.


Wednesday, October 7, 2015 2:36 AM | 1 vote

Hi Mark,

Yes Windows Powershell 5.0 now uses syntax coloring, just as in Windows PowerShell ISE.

This is listed here: https://technet.microsoft.com/en-us/library/hh857339.aspx#BKMK_new50

By the way, we may right click on the powershell title, then select properties:

In addition, to use command, try the:

$host.privatedata

Changing the error foreground color is as below:

$host.PrivateData.ErrorForegroundColor = 'White'

For the command, sorry to say that currently I have no idea.

For more information, please consider seek help at hte powershell forum.

Regards

Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected].


Monday, October 12, 2015 7:01 PM

Unfortunately, this does not answer my question, but thank you for the response.


Monday, October 12, 2015 7:04 PM

Again, apologies, but this does not address my problem, so I'm unmarking it.  If I can figure out an answer, I'll post it here.


Tuesday, October 13, 2015 1:15 AM

Hi Mark,

Thanks for your sharing.

If any further questions, please feel free to post in TechNet.

Regards

Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected].


Friday, September 23, 2016 1:54 PM

Thank you x 1,000,000 Mark. I have been "dealing" with my console string token -foreground being set to Dark Magenta...against a dark magenta background. I know I stumbled across these commands a while back but must have had bad data.  This made my day...yes, I know...getting a display font shouldn't make someone's day, but it's been a long time dealing with this, ashamedly.


Monday, March 4, 2019 2:39 PM

Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'TokenKind'.
At C:\Users\Kevin\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:1 char:22

  • Set-PSReadlineOption -TokenKind comment -ForegroundColor white
    +                      ~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Set-PSReadLineOption], ParameterBindingException
        + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.SetPSReadLineOption

I have been trying to get this fixed for weeks, hundreds of answers that do not work.


Monday, March 4, 2019 3:22 PM | 1 vote

Set-PSReadLineOption -Colors @{
"ContinuationPrompt" =     [ConsoleColor]:: White
"Emphasis" =     [ConsoleColor]:: White    
"Error" =     [ConsoleColor]:: White
"Selection" =     [ConsoleColor]:: White
"Default" =     [ConsoleColor]:: White
"Comment" =     [ConsoleColor]:: White
"Keyword" =     [ConsoleColor]:: White
"String" =     [ConsoleColor]:: White
"Operator" =     [ConsoleColor]:: White
"Variable" =     [ConsoleColor]:: White
"Command" =     [ConsoleColor]:: White
"Parameter" =     [ConsoleColor]:: White
"Type" =     [ConsoleColor]:: White
"Number" =     [ConsoleColor]:: White
"Member" =     [ConsoleColor]:: White
}


Wednesday, March 6, 2019 4:51 PM

That worked for me. Thanks for the advice.