Skip to content

Instantly share code, notes, and snippets.

@45413
Created April 27, 2018 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 45413/c805ffde4b317ca2c9af5b8498f9be3e to your computer and use it in GitHub Desktop.
Save 45413/c805ffde4b317ca2c9af5b8498f9be3e to your computer and use it in GitHub Desktop.
Powershell function to enumerate all available console colors - with examples
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