Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell Color Combos

Posted on October 1, 2020October 1, 2020

A lot of my PowerShell work lately has involved color. I find myself using ANSI escape sequences quite often. I'm also playing with different color schemes in Windows Terminal. And I still on occasion find myself using Write-Host to display colorized messages. What has gotten trickier is that Windows Terminal schemes can redefine colors. What I am used to as Green may not actually be Green. I polished up a simple script, to display all possible combinations for the console colors.

#requires -version 5.1

#Display a combination of foreground and background console colors

#create an array of system console colors
$colors = [enum]::GetNames([consolecolor])

<#
 combine the color as foreground in combination with every color
 as a background
#>
foreach ($bg in $colors) {
  Clear-Host
  foreach ($fg in $colors) {
    $msg = "This is a $fg foreground on a $bg background"
    Write-Host $msg.PadRight(75, ' ') -ForegroundColor $fg -BackgroundColor $bg
  } #foreach $bg

  #pause for each background
  Write-Host " "
  Pause
} #foreach $fg

The script will cycle through all of the console colors, pausing after each. Here's what this looks like in a traditional Windows PowerShell session.

This makes it easy to identify a good color combination. But notice what happens in Windows Terminal.

You can see that DarkGreen isn't really what it says it is. But, this helps me select an appropriate console color.

Not all my Windows Terminal color schemes are as quite dramatic as this one, but regardless, I now have a quick script I can run to get a preview of what I can expect. Hope you find this handy.

Share this:

  • Print (Opens in new window) Print

Like this:

Like Loading…

Related

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2026 The Lonely Administrator | Powered by SuperbThemes!
%d