I posted a new wiki doc that explains how you can change the syntax highlighting colors of the PSReadLine module that comes with PowerShell. The doc also describes how you change the general console colors with PowerShell. However, I  ran into some trouble with the Set-PSReadlineOption cmdlet. Maybe you can help?

Michael Pietroforte

Michael Pietroforte is the founder and editor of 4sysops. He is a Microsoft Most Valuable Professional (MVP) with more than 30 years of experience in IT management and system administration.

Colors are a matter of taste. Many of the older geeks prefer a console with a black background and a green foreground color. I suppose it reminds them of the good old days when we only had monochrome computer screens (so-called green screens) and Paul Allen and Steve Wozniak had not yet stolen the GUI technology from Xerox PARC.

Computer screens in the good old days

Computer screens in the good old days

Thus, I guess many hardcore console enthusiasts didn't really like it when Microsoft included PSReadLine in PowerShell 5. I already liked the module before that. I like colors. I find syntax highlighting quite helpful for avoiding typos and, in my view, it not only makes sense for scripting but also on a console.

The problem is that when you change the background color of your console (through the console properties), the default PSReadLine colors often don't fit anymore. The good thing is that you can change the default PSReadLine colors, although it is not as straightforward as in modern terminal applications where you can often choose from a wide range of colors in a GUI. The PowerShell console offers only a very limited number of colors. I explained everything in detail in the wiki. Please help improve the document by editing it.

In theory, the Set-PSReadlineOption cmdlet allows you to do more than set the colors of tokens. According to Microsoft's documentation, the cmdlet also supports parameters such as -ContinuationPromptForegroundColor, -ContinuationPromptBackgroundColor, -EmphasisForegroundColor, -EmphasisBackgroundColor, -ErrorForegroundColor, and -ErrorBackgroundColor.

For instance, to set the background color for errors to blue, this command is supposed to make the change:

Changing the background color for error messages is not working

Changing the background color for error messages is not working

In practice, this command didn't work for me. It didn't throw an error message in my test, but it didn't change the colors, either. Maybe I misunderstood something here? Enlighten me please!

Win the monthly 4sysops member prize for IT pros

Share
1+

Related Posts

3 Comments
  1. Leos Marek 3 weeks ago

    Hi Michael,

    you can refer to this post to get the answer.

    Its because the functionality you are looking for is not provided by PSreadline, but its console settings (get-host).

    Hope it helps

    Leos

    0

  2. Author
    Michael Pietroforte 3 weeks ago

    Leos, thanks. I explained all the possible ways of how to change the PowerShell console colors in the wiki. Actually, more options exist than mentioned in the Technet article.

    However, I wonder what PSReadline parameters like -ErrorBackgroundColor are for? They seem to have no effect. A bug?

    0

  3. Leos Marek 3 weeks ago

    I dont have answer for that. But its not what you asked in your original post showing error message with unknown command. Thats not controlled by PSreadline but by the settings of console 🙂

    I wish you Happy New Year and a lot of motivation to continue the good work with this site 🙂

    Ill deliver my article during January 🙂

    Leos

    0

Leave a reply

Your email address will not be published. Required fields are marked *

*

CONTACT US

Please ask IT administration questions in the forum. Any other messages are welcome.

Sending
© 4sysops 2006 - 2018

Log in with your credentials

or    

Forgot your details?

Create Account