Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Powershell colors with hex values in profile script

I know I can change PowerShell console colors by setting in my profile something like:

$Host.UI.RawUI.BackgroundColor = "White"
Clear-Host

However in the Powershell Console one can go to the Color tab in Properties and modify the RGB values of the standard 16 ANSI colors manually. Is it possible to do set either hex or RGB values of the standard colors from the profile script? For instance setting I would like to have:

$Host.UI.RawUI.BackgroundColor = "#242424"  # Gray
Clear-Host
like image 508
petobens Avatar asked Apr 29 '13 13:04

petobens


People also ask

How do you add a hex color code?

Hex color codes start with a pound sign or hashtag (#) and are followed by six letters and/or numbers. The first two letters/numbers refer to red, the next two refer to green, and the last two refer to blue. The color values are defined in values between 00 and FF (instead of from 0 to 255 in RGB).

How do I change the color of text in a PowerShell script?

Font color is termed as the Foreground color in the PowerShell. To change the font color you can use the console GUI property “Screen Text”. There are various 16 colors available and you can change RGB properties as well.

How do I change the default color in PowerShell?

Copy the ones you want to reset to their default color settings, and paste them in your "C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" folder. That's it!


1 Answers

The correct way to do this is with the Registry

cd hkcu:/console
$0 = '%systemroot%_system32_windowspowershell_v1.0_powershell.exe'
ni $0 -f
sp $0 ColorTable00 0x00562401
sp $0 ColorTable07 0x00f0edee

With the color being

0x00BBGGRR
like image 166
Zombo Avatar answered Oct 10 '22 09:10

Zombo