Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List of all colors available for PowerShell?

I am searching for a list of all colors I can use in PowerShell. Since we need to provide names and no hexnumbers, it's hard to figure out if a color exists or not, at least if you don't know how :))

For example, as -foregroundcolor

write-host "hello world" -foregroundcolor "red"
like image 878
RayofCommand Avatar asked Dec 12 '13 10:12

RayofCommand


People also ask

What are the default PowerShell colors?

As mentioned earlier, Windows PowerShell console displays white on blue by default and red on black for error messages, so to change colors, right-click on the PowerShell Window top-bar, and select 'Properties'.

How do I add color in PowerShell?

You can specify the color of text by using the ForegroundColor parameter, and you can specify the background color by using the BackgroundColor parameter. The Separator parameter lets you specify a string to use to separate displayed objects. The particular result depends on the program that is hosting PowerShell.

What does red mean in PowerShell?

This time, $profile remains red inside the brown text. It indicates that it is still viewed as a variable and treated accordingly. So in PowerShell 3.0, color highlighting has risen to new standards, and it can help a lot to appreciate and acknowledge what it wants to tell you.

How do I change font color in PowerShell?

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.


4 Answers

Pretty grid

$colors = [enum]::GetValues([System.ConsoleColor])
Foreach ($bgcolor in $colors){
    Foreach ($fgcolor in $colors) { Write-Host "$fgcolor|"  -ForegroundColor $fgcolor -BackgroundColor $bgcolor -NoNewLine }
    Write-Host " on $bgcolor"
}

screenshot of colourful output

Updated colours in newer powershell:

screenshot of colourful output

https://gist.github.com/timabell/cc9ca76964b59b2a54e91bda3665499e

like image 150
Tim Abell Avatar answered Oct 21 '22 19:10

Tim Abell


The console colors are in an enum called [System.ConsoleColor]. You can list all the values using the GetValues static method of [Enum]

[Enum]::GetValues([System.ConsoleColor])

or just

[Enum]::GetValues([ConsoleColor])
like image 28
mjolinor Avatar answered Oct 21 '22 20:10

mjolinor


How about checking the help? Like so, get-help write-host will tell you:

[-BackgroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed | DarkMagenta | DarkYellow | Gray | DarkGray | Blue | Green | Cyan | Red | Magenta | Yellow | White}]
[-ForegroundColor {Black | DarkBlue | DarkGreen | DarkCyan | DarkRed | DarkMagenta | DarkYellow | Gray | DarkGray | Blue | Green | Cyan | Red | Magenta | Yellow | White}]
like image 11
vonPryz Avatar answered Oct 21 '22 20:10

vonPryz


I've found it useful to preview how the console colors will display with a simple helper function:

function Show-Colors( ) {
  $colors = [Enum]::GetValues( [ConsoleColor] )
  $max = ($colors | foreach { "$_ ".Length } | Measure-Object -Maximum).Maximum
  foreach( $color in $colors ) {
    Write-Host (" {0,2} {1,$max} " -f [int]$color,$color) -NoNewline
    Write-Host "$color" -Foreground $color
  }
}
like image 22
Emperor XLII Avatar answered Oct 21 '22 21:10

Emperor XLII