Partager via


Sample all PowerShell Console Colors

I often need to pick console colors to use making host text a little easier to look at (coupled with smart indentation).  The –Foregroundcolor parameter of the Write-Host cmdlet is what I commonly use to set text colors.  I like to use lots of colors, but sometimes I forget what all the colors are and what they look like (the look is more important).  The Intellisense in the v3+ ISE is great that it suggests the color names (tab completion will as well), but sometimes I need to be reminded of what each looks like.  Here is a simple little one-liner that will show the color names in their appropriate color.  I use this line every so often to remind me.

PS > [enum]::GetValues([System.ConsoleColor]) | Foreach-Object {Write-Host $_ -ForegroundColor $_}      

Black

DarkBlue      

DarkGreen      

DarkCyan      

DarkRed      

DarkMagenta      

DarkYellow      

Gray      

DarkGray      

Blue      

Green      

Cyan    

Red      

Magenta      

Yellow

White <-- White is here, but you can’t see it)

Hopefully this trick helps someone out.

-Gary Siepser

Comments

  • Anonymous
    January 01, 2003
    SCCM
  • Anonymous
    May 20, 2014
    Thanks for this
  • Anonymous
    February 02, 2015
    Thanks for this, just what I needed :)
  • Anonymous
    March 05, 2015
    DarkMagenta is actually more blue-ish. default background of the console.
  • Anonymous
    April 12, 2015
    Very nice and thanks. In the "give an inch and take a mile" method I would like to ask one more question. How would we take each of those colors and try each of them to show on each of the possible back ground colors? Basically creating a pallet so you can see what you want for best flare and more important for my old eyes best contrast for readability.
  • Anonymous
    April 24, 2015
    $colors = [enum]::GetValues([System.ConsoleColor])
    foreach( $fcolor in $colors )
    {
    foreach( $bcolor in $colors )
    {
    Write-Host "ForegroundColor is : $fcolor BackgroundColor is : $bcolor "-ForegroundColor $fcolor -BackgroundColor $bcolor
    }
    }
  • Anonymous
    August 12, 2015
    Change your UI


    #Create variable with all colors

    $colors = [enum]::GetValues([System.ConsoleColor]) #| Foreach-Object {Write-Host $_ -ForegroundColor $}

    #$colors | Foreach-Object {Write-Host $
    -ForegroundColor $_}



    #get two random numbres

    $randomint1 = Get-Random -Minimum 0 -Maximum $colors.Length

    $randomint2 = Get-Random -Minimum 0 -Maximum $colors.Length

    #$randomint1

    #$randomint2



    #set two random color varibles

    $color1 = $colors.GetValue($randomint1)

    $color2 = $colors.GetValue($randomint2)

    #$color1

    #$color2



    #set host UI colors

    $Host.ui.RawUI.BackgroundColor = $color1

    $Host.UI.RawUI.ForegroundColor = $color2



    #Set whole window

    cls



  • Anonymous
    August 14, 2015
    Random UI Color
    Updated


    [tag:Get] System Colors
    $colors = [enum]::GetValues([System.ConsoleColor])

    $colors



    #Create while variables
    $int1 = 0

    $int2 = 0



    )#DARK LIGHT/LIGH DARK loop
    while($int1 -eq 0

    {

    )#Random Int loop
    while($int2 -eq 0

    {
    [tag:Get] two int. compare for match
    $randomint1 = Get-Random -Minimum 0 -Maximum ($colors.Length-1)

    $randomint2 = Get-Random -Minimum 0 -Maximum ($colors.Length-1)

    if($randomint1 -ne $randomint2)

    {

    $int2 = 1
    }

    }#end random int loop

    $randomint1

    $randomint2



    [tag:Get] colors from $colors variable using two random int
    $color1 = $colors.GetValue($randomint1)

    $color2 = $colors.GetValue($randomint2)

    if($color1 -match "dark" -and $color2 -notmatch "dark" -and $color2 -notmatch "black")

    {

    Write-Host "DARK LIGHT MATCH"

    $int1 = 1

    }

    elseif($color1 -notmatch "dark" -and $color2 -match "dark" -and $color1 -notmatch "black")

    {

    Write-Host "LIGHT DARK MATCH"

    $int1 = 1

    }

    else

    {

    Write-Host "BOTH/NO MATCH"

    $int2 = 0

    }


    }#end DARK LIGHT/LIGHT DARK loop

    $color1

    $color2



    [tag:Set] Host UI fore and background colors
    $Host.UI.RawUI.BackgroundColor = $color1

    $Host.UI.RawUI.ForegroundColor = $color2



    [tag:Set] whole screen to current host UI colors
    cls
  • Anonymous
    September 10, 2015
    Some of the colors in the Powershell Window look to be custom colors. Look at the colors available above and those in the window. I think you'd need to be able to specify the rgb values