Change Colors Used by the Windows PowerShell ISE

ScriptingGuy1

Summary: Learn how to change colors used by the Windows PowerShell ISE to customize your scripting environment.

 

Microsoft Scripting Guy Ed Wilson here. One of the things that is kind of lame about Charlotte is that there is not a good computer store. This is a rather surprising revelation considering the heavy concentration of high-tech workers in the area. It might be that one actually exists. However, after spending over an hour on the Internet and even spamming several of my fellow Microsoft workers, I struck out. It might be that I am picky. What I call a good computer store is a store the size of an American football stadium that has one really long aisle devoted to power supplies, another long aisle devoted to KVM switches (keyboard, video, mouse), and at least half of an aisle dedicated to CMOS batteries. Not to mention hard disk drives, cases, CPUs, motherboards, and all of the other fun things that go along with building a computer.

I happen to be a hardware geek from way back. One of the reasons I love Windows Management Instrumentation (WMI) is because of all the cool information I can pick up about hardware. I am planning some more hardware-related Hey, Scripting Guy! Blog posts in the next few weeks. For now, let me push a stack of stuff out of the way, and make room for my laptop so that I can spend some time playing with the Windows PowerShell ISE. Oh, no, a female humanoid with a camera. Dude, too late. She got me.

Photo of Ed "Hardware" Wilson

Last weekend, I discussed customizing the Windows PowerShell ISE, and I pointed out that the colors are all instances of the System.Windows.Media.Colors .NET Framework class.

While it is true that the MSDN documentation that covers the colors class includes a helpful chart of the colors, I am not always connected to the Internet, and therefore I need to be able to discover information on my own. When I am exploring, I like to use the Get-Member cmdlet. By passing the .NET Framework class inside a set of square brackets, static properties of a class can be revealed. This is shown here:

[windows.media.colors] | Get-Member -Static -MemberType property

Each color is returned as a static property from the colors class. The name of the static property is converted to a string and passed to the OutputPaneTextBackgroundColor property of the $psISE.options. This causes the background color that is found behind the text in the output pane to change to the color that is current in the loop. This is shown here:

$psISE.Options.OutputPaneTextBackgroundColor = ` 
([windows.media.colors]::$($_.name)).ToString()

The thing that took a bit of experimentation was the portion of the code that displays the name of the color, as well as the hexadecimal value of the color. The name of the color comes across the pipeline as the name property of the object. Next a `t is used to tab over one tab stop. When a specific color is referenced by static property name from the colors class, the makeup of the color is displayed as combination of ARGB. This is seen here.

PS C:\Users\ed.NWTRADERS> [windows.media.colors]::aqua 
ColorContext : 
A : 255 
R : 0 
G : 255 
B : 255 
ScA : 1 
ScR : 0 
ScG : 1 
ScB : 1

To use the AGRB values for a color, the hexadecimal version of the AGRB values is required. This can be returned by using a subexpression to force evaluation of the color property inside a string. This is easier done than said, as is seen here.

PS C:\Users\ed.NWTRADERS> “$([windows.media.colors]::aqua)”

#FF00FFFF

 

That is basically all there is to the Get-PSIseColorValues.ps1 script. The complete script is seen here.

Get-PsIseColorValues.ps1

[windows.media.colors] | Get-Member -Static -MemberType property | 
ForEach-Object { 
$psISE.Options.OutputPaneTextBackgroundColor = `
([windows.media.colors]::$($_.name)).tostring() 
“$($_.name) `t $([windows.media.colors]::$($_.name))” 
}

When the Get-PSIseColorValues.ps1 script runs, the output shown in the following image is displayed.

Image of output displayed when script runs

Join me tomorrow as I pull together the things we have looked at both today and last weekend into a single script that will create a custom menu in the Windows PowerShell ISE. It is way cool. We would love you to follow us on Twitter or Facebook. If you have any questions, send email to us at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

 

Ed Wilson and Craig Liebendorfer, Scripting Guys

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • J S 0

    OutputPaneTextBackgroundColor doesn’t seem to exist anymore.  But listing the color names is useful.

    • David Corkill 0

      In my ISE the option is named ConsolePaneTextBackgroundColor

Feedback usabilla icon