Beetle
Beetle

Reputation: 189

Set background color other then standard one in Powershell

I can change console background color by script:

$host.UI.RawUI.BackgroundColor = "Black"

but in this case I'm limited to preset number of defined colors and unfortunately one I'm looking for is not here. There is option to pick color from console GUI (right click on top Windows PowerShell bar->properties->Colors). Unfortunately (again) only BackGroundColor and ForeGroundColor can be changed there, no way to change one of $host.privatedata colors there.

Is there possibility to put hex coded color via script somehow?

Upvotes: 6

Views: 8220

Answers (2)

Kip
Kip

Reputation: 558

In my view, Powershell should allow you to set colors to a rgb hex value rather than the predefined set of colors. But design questions aside, the way I worked around this was to create a .reg file to redefine the "color buckets" (which they call ColorTables) that Powershell uses. The code below includes comments indicating what the specific ColorTable controls in Powershell.

Notes:

  1. To save your current colors first, open regedit and export HKCU\Console.
  2. Save the code below to a file (e.g. colors.reg), and run it.
  3. Create a shortcut pointing to powershell. Run it. It should have new colors.
  4. To modify colors, set the appropriate ColorTableXX dword to the hex value, but note, the RGB values are actually BGR, and they need to be padded with 00 in front of the number. So a blue color, #4286f4, would have a dword of 00f48642.

colors.reg:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Console]
; BACKGROUND
"ColorTable07"=dword:00efefef

; ERROR BACKGROUND
"ColorTable00"=dword:00efefef

;ERROR
"ColorTable12"=dword:00255ffc

; STATIC TEXT (PROMPT and OUTPUT) AND COMMAND ARGUMENT
"ColorTable01"=dword:00472713

; COMMAND TEXT
"ColorTable14"=dword:00c56e36

; COMMAND TEXT SELECTED
"ColorTable09"=dword:00ef47d3

; COMMAND FLAG
"ColorTable08"=dword:00a53733

; COMMAND FLAG SELECTED
"ColorTable15"=dword:00ef47d3

; COMMMAND ARGUMENT SELECTED
"ColorTable06"=dword:00ef47d3

; COMMAND VARIABLE (e.g. $profile)
"ColorTable10"=dword:00a53733

; COMMAND VARIABLE SELECTED
"ColorTable13"=dword:00ef47d3

; deep purple -- not sure what this is
"ColorTable04"=dword:00660566

; brown -- not sure what this is
"ColorTable05"=dword:00336699

; purple -- not sure what this is
"ColorTable11"=dword:00845f84

; green -- not sure what this is
"ColorTable02"=dword:00339933

; pastel lavendar -- not sure what this is
"ColorTable03"=dword:00FF9999

Upvotes: 2

Loïc MICHEL
Loïc MICHEL

Reputation: 26180

there is a registry hack here : http://stackingcode.com/blog/2011/11/14/zenburn-powershell

Upvotes: 2

Related Questions