Created
April 27, 2018 02:10
-
-
Save 45413/c805ffde4b317ca2c9af5b8498f9be3e to your computer and use it in GitHub Desktop.
Powershell function to enumerate all available console colors - with examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Enumerate-ConsoleColors { | |
[CmdletBinding()] | |
param ( | |
# Print Example Switch | |
[Parameter(Mandatory=$false)] | |
[Alias("Example","ex","print")] | |
[Switch] | |
$PrintExamples=$false | |
) | |
# Enumerate Names of [System.ConsoleColor] Class | |
$colors = [System.Enum]::GetNames([System.ConsoleColor]) | |
if ($PrintExamples) { | |
# Loop over each color setting the background color | |
foreach ($bg in $colors) { | |
# Loop over each color setting the foreground color | |
foreach ($fg in $colors) { | |
# Make sure we are not printing the same color foreground and background | |
if ($bg -ne $fg) { | |
# Otherwise print example | |
write-host $fg -ForegroundColor $fg -BackgroundColor $bg -NoNewline ; Write-Host " - $fg on $bg" | |
} | |
} | |
} | |
} else { | |
return $colors | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment