PoshBytes Versus: Holiday Color Rumble – Write-Host vs ANSI vs PSStyle
In this PoshBytes Versus we pit Write-Host -ForegroundColor against ANSI escape sequences and $PSStyle.Foreground in a three way holiday color showdown using an ASCII Christmas tree and menorah. See how to go from basic console colors to full RGB lights without setting your terminal on fire.
This post is a companion for the video embedded below. Scroll down to see the code from the video.
Warm up – Get some art to draw
Holiday ASCII art
$tree = @'
*
/\
/ \
/~~\o
/o \
/~~*~~~\
o/ o \
/~~~~~~~~\~`
/__*_______\
||
\====/
\__/
'@
$menorah = @'
(
( ) ) ( () ) ( ( )
() () () () ǁǁ () () () ()
ǁǁ ǁǁ ǁǁ ǁǁ _ǁǁ_ ǁǁ ǁǁ ǁǁ ǁǁ
_ǁǁ_ _ǁǁ_ _ǁǁ_ _ǁǁ_ | | _ǁǁ_ _ǁǁ_ _ǁǁ_ _ǁǁ_
| | | | | | | | | | | | | | | | | |
\ / \ / \ / \ / \ / \ / \ / \ / \ /
\ \ \ \ \ \ \ \__| |__/ / / / / / / /
\ \ \ \ \ \ '.__ __.' / / / / / /
\ \ \ \ \ '-.___| |___.-' / / / / /
\ \ \ \ '-.____ ____.-' / / / /
\ \ \ '-.______| |______.-' / / /
\ \ '-._______ _______.-' / /
\ '-._________| |_________.-' /
'-.__________ __________.-'
_______| |_______
\________________/
'@
Round 1 – Write-Host with -ForegroundColor (The Classic Holiday Lights)
Classic console single color options
Write-Host $tree -ForegroundColor Green
Write-Host $menorah -ForegroundColor Yellow
Round 2 – ANSI Escape Sequences with RGB (Manual, but Powerful)
Make sure your terminal supports ANSI (Windows Terminal, VS Code, etc.)
Write-Host "`e[38;2;0;255;0m$tree`e[0m"
Write-Host "`e[38;2;0;191;255m$menorah`e[0m"
Round 3 – $PSStyle.Foreground with RGB (PowerShell 7’s Holiday Upgrade)
RGB Christmas tree using PSStyle
$PSStyle.OutputRendering = 'Ansi'
$rgbTree =
$PSStyle.Foreground.FromRgb(0x00FF00) + $tree +
$PSStyle.Foreground.FromRgb(0xFFD700) + "`nStar upgrade included`n" +
$PSStyle.Reset
Write-Host $rgbTree
RGB Menorah using PSStyle
$rgbMenorah =
$PSStyle.Foreground.FromRgb(0x00BFFF) + $menorah +
$PSStyle.Foreground.FromRgb(0xFFFFAA) + "`nFestival of precise RGB`n" +
$PSStyle.Reset
Write-Host $rgbMenorah
Round 4 – $PSStyle.Foreground with an RGB Color Map (Each Character Gets a Costume)
Function Write-RGBHost {
Param (
[string]$Text,
[hashtable]$ColorMap
)
$builder = [System.Text.StringBuilder]::new()
foreach ($ch in $Text.ToCharArray()) {
# If we have a color for this character, apply it
if ($ColorMap.ContainsKey($ch.ToString())) {
[void]$builder.Append($ColorMap[$ch.ToString()])
}
# Append the character itself
[void]$builder.Append($ch)
# On newline, reset so the right edge doesn’t smear color across lines
if ($ch -eq "`n") {
[void]$builder.Append($PSStyle.Reset)
}
}
# Final colored tree string with a reset at the end for safety
$rgbOutput = $builder.ToString() + $PSStyle.Reset
Write-Host $rgbOutput
}
Map characters in the tree to specific colors
$treeColorMap = @{
'*' = $PSStyle.Foreground.FromRgb(0xFFD700) # gold star / sparkles
'o' = $PSStyle.Foreground.FromRgb(0xFF4500) # ornaments
'~' = $PSStyle.Foreground.FromRgb(0x00FF00) # branches
'/' = $PSStyle.Foreground.FromRgb(0x008000) # tree edges
'\' = $PSStyle.Foreground.FromRgb(0x008000) # tree edges
'|' = $PSStyle.Foreground.FromRgb(0x8B4513) # trunk
'=' = $PSStyle.Foreground.FromRgb(0x8B4513) # stand
'_' = $PSStyle.Foreground.FromRgb(0x654321) # base
}
Write-RGBHost -Text $tree -ColorMap $treeColorMap
$menorahColorMap = @{
'(' = $PSStyle.Foreground.FromRgb(0xFFD700) # flame (gold)
')' = $PSStyle.Foreground.FromRgb(0xFFD700) # flame (gold)
'_' = $PSStyle.Foreground.FromRgb(0x87CEEB) # candle body highlight
'ǁ' = $PSStyle.Foreground.FromRgb(0x1E90FF) # candle body (blue)
'|' = $PSStyle.Foreground.FromRgb(0xC0C0C0) # menorah frame (silver)
'/' = $PSStyle.Foreground.FromRgb(0xA9A9A9) # structure angle
'\' = $PSStyle.Foreground.FromRgb(0xA9A9A9) # structure angle
'.' = $PSStyle.Foreground.FromRgb(0xFFD700) # spark/glow
'-' = $PSStyle.Foreground.FromRgb(0x708090) # shading for base
' ' = '' # leave spaces unstyled
}
Write-RGBHost -Text $menorah -ColorMap $menorahColorMap
Wrap Up
• Write-Host -ForegroundColor is simple and great for quick, readable scripts but limited to the console palette.
• ANSI escape sequences unlock full RGB control with e[38;2;R;G;B codes, but require a double quote here-string so backtick escapes and variables are processed.
• $PSStyle.Foreground in PowerShell 7+ gives you friendly methods like FromRgb while still outputting ANSI under the hood.
• Always reset your styles (e[0m or $PSStyle.Reset) so your console does not stay accidentally festive forever.
• Choose based on your needs: compatibility and simplicity vs fine grained RGB control and style composition.