Powershell: Console Colors
A brief reminder for the topic of Console Colors and Powershell.
Contents
Get the current console/color setup
> $Host.Version.ToString()
5.1.19041.6093
> $Host.UI.RawUI.BackgroundColor
Black
> $Host.UI.RawUI.ForegroundColor
Gray
# Other Host colors which can be set by assining a different:
> $Host.PrivateData
ErrorForegroundColor : Red
ErrorBackgroundColor : Black
WarningForegroundColor : Yellow
WarningBackgroundColor : Black
DebugForegroundColor : Yellow
DebugBackgroundColor : Black
VerboseForegroundColor : Yellow
VerboseBackgroundColor : Black
ProgressForegroundColor : Yellow
ProgressBackgroundColor : DarkCyan
> Get-PSReadLineOption
EditMode : Windows
# ...
VariableColor : "$([char]0x1b)[92m"
Setting new colors
Next to the 16 predefined color names one can also use ANSI Escape Codes
for defining a color theme – but those are a bit too complicated to explain it here in detail (see the Color entries of Get-PSReadLineOption for examples):
> [System.ConsoleColor].GetEnumNames()
Black
# ...
> Get-PSReadLineOption
# ...
SelectionColor : "$([char]0x1b)[30;47m"
StringColor : "$([char]0x1b)[36m"
# ...
Example
The following changes it will only be active in the current Powershell session!
To change the colors permanently, put it into your Powershell profile.
$Host.UI.RawUI.BackgroundColor = 'Black'
$Host.UI.RawUI.ForegroundColor = 'Gray'
$Host.PrivateData.ErrorForegroundColor = 'Red'
# ...
$NewColorTheme = @{
CommandColor = "$([char]0x1b)[93m"
...
SelectionColor = "$([char]0x1b)[30;47m"
StringColor = "$([char]0x1b)[36m"
TypeColor = "$([char]0x1b)[37m"
VariableColor = "$([char]0x1b)[92m"
}
Set-PSReadLineOption -Colors $NewColorTheme
Categories
Development (78)Film & Television (55)
How To (64)
Journal (17)
Miscellaneous (4)
News & Announcements (21)
On Software (12)
Projects (26)
Tags
Bluetooth (1)
C++ (11)
Citrix (1)
Clang (1)
CMake (10)
Code (3)
DE (8)
Doxygen (1)
EN (177)
Excel (1)
Filezilla (1)
Firefox (1)
GeSHi (1)
Git (2)
Hugo (2)
JSON (2)
Lua (3)
Mercurial (5)
MTP (2)
Notepad++ (3)
Powershell (24)
PuTTY (1)
Python (5)
Qt (11)
RandFill (15)
RegEx (1)
Remi (2)
RSS (1)
SCons (1)
SIMInfo (7)
Site (2)
SSH (1)
TinyTinyRSS (1)
Using C++ With Lua (2)
Visual Studio (10)
Win32 (2)
Windows (22)
Windows Registry (1)
WordPress (3)
WPD (3)
WPDLib (2)
WPF (1)
XAML (1)
YouTube (1)