PowerShell improves on the (frankly) fugly Windows Console colour scheme by assigning a bluish value to one of its 16 console colours ( - the one known as DarkMagenta for some reason - ), and uses this as the default screen background.
I want to programmatically change each of the 16 colours to a custom colour scheme. In my PowerShell profile, for example.
I've found explanations on how to change which one of the ConsoleHost's 16 colours gets assigned to different kinds of text, but what I want is to actually change each of the ConsoleHost's 16 colours to a different hex value. (For myself only, not for other users, or other consoles, such as cmd.exe
.)
Of course this can be done by right-clicking the menu bar and manually adjusting the "Properties" or "Default" settings, but this gets very quickly tiring. And I cannot locate where these settings get persisted.
(I have already searched the registry and C:\Users\<current_user>\AppData
, and found nothing, except for the ColorTable##
properties under HKCU:\Console
, whose scope is obviously broader than the PowerShell console settings.)
If anyone can help, it would be greatly appreciated.
The console colors are defined in multiple places:
- Global/Default:
HKCU:\Console
. This applies to all conhost.exe
-applications including cmd.exe
and powershell.exe
.
- Per process:
HKCU:\Console\<PROCESS_PATH_WITH_UNDESCORE>
for process-specific changes. Ex. HKEY_CURRENT_USER\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe
is defined and has modified ColorTable05
and ColorTable06
.
- Per shortcut: Inside the shortcut (.lnk). This is hard to modify programmatically, would probably require P\Invoke.
You can modify the process-level values with PS using:
Set-ItemProperty -Path "HKCU:\Console\%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe" -Name ColorTable04 -Value 5645313
Be aware that to see the values of the process-level you need start PS using run, windows explorer etc. If you use one of the shortcuts, then the shortcut's values will be used. So it might be easier to modify the shortcut and keep a copy of it for new setups.
Each "ColorTable" has a name hardcoded in the System.ConsoleColor-enum, so it's just "random" that they used the one called DarkMagneta. Probably because it's a unique color that isn't used that much.
I searched for "change powershell console color" and found tons of examples.
Perhaps this is what you are looking for:
How can I set the PowerShell console background color
$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'DarkBlue')
$Host.UI.RawUI.ForegroundColor = 'White'
$Host.PrivateData.ErrorForegroundColor = 'Red'
$Host.PrivateData.ErrorBackgroundColor = $bckgrnd
$Host.PrivateData.WarningForegroundColor = 'Magenta'
$Host.PrivateData.WarningBackgroundColor = $bckgrnd
$Host.PrivateData.DebugForegroundColor = 'Yellow'
$Host.PrivateData.DebugBackgroundColor = $bckgrnd
$Host.PrivateData.VerboseForegroundColor = 'Green'
$Host.PrivateData.VerboseBackgroundColor = $bckgrnd
$Host.PrivateData.ProgressForegroundColor = 'Cyan'
$Host.PrivateData.ProgressBackgroundColor = $bckgrnd
Clear-Host
There is also another discussion on the topic at:
Setting Powershell colors with hex values in profile script
I have made a utility for Windows console colors called Concfg.
It can import colours from JSON preset files, and takes care of removing the overrides from the registry and .lnk files.