Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active February 28, 2024 08:40
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save timabell/cc9ca76964b59b2a54e91bda3665499e to your computer and use it in GitHub Desktop.
Save timabell/cc9ca76964b59b2a54e91bda3665499e to your computer and use it in GitHub Desktop.
output all the colour combinations for text/background in powershell https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell/41954792#41954792
# output all the colour combinations for text/background
# https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell/41954792#41954792
$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"
}
@B4Art
Copy link

B4Art commented Dec 14, 2020

If you sort the Colors you can show them beneath each other:

$colors = [enum]::GetValues([System.ConsoleColor]) | Select-Object @{N='ColorObject';E={$_}}, @{N='ColorName'; E={ If ($_.ToString().substring(0,3) -eq 'Dar' ){ $_.ToString().Substring(4) + 'DARK' } else { $_.ToString() } } } | Sort-Object Colorname ; Foreach ($bgcolor in $colors.ColorObject){ Foreach ($fgcolor in $colors.ColorObject) { Write-Host "$fgcolor|" -ForegroundColor $fgcolor -BackgroundColor $bgcolor -NoNewLine } Write-Host " on $bgcolor" }

Added a ";" for those that copy from view.

@pkutaj
Copy link

pkutaj commented Sep 18, 2021

The function has a front seat in my $profile and each time I run colors, it's just a wonderfully elegant aesthetic experience. Beauty Is Our Business. Thanks a lot.
img003121

@timabell
Copy link
Author

You're welcome @pkutaj

Thanks for the tip @B4Art

💟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment