header image

PowerShell colours

Posted by: | January 14, 2011 | No Comment |

The background and text colours for a PowerShell instance (not ISE) can be set through the properties of the window. There are a set of colours for the background and text of:

  • Error messages
  • Warning Messages
  • Debug info
  • Verbose output
  • Progress bars

that cannot be set in this manner.

There is a PowerShell 2.0 automatic variable called $host that will display information about the current instance of PowerShell.

These two facts are related how?

$host has a property called privatedata. This isn’t some super secret hidey hole to tuck away the bits of information you don’t want anyone else to read. It actually contains the colour settings we discussed above. On a default PowerShell install you will get:

PS> $host.privatedata

ErrorForegroundColor    : Red
ErrorBackgroundColor    : Black
WarningForegroundColor  : Yellow
WarningBackgroundColor  : Black
DebugForegroundColor    : Yellow
DebugBackgroundColor    : Black
VerboseForegroundColor  : Yellow
VerboseBackgroundColor  : Black
ProgressForegroundColor : Yellow
ProgressBackgroundColor : DarkCyan


These settings can be changed by simply put a line such as

$host.privatedata.ErrorBackgroundColor = "White"

into your profile.  If you only want a temporary change simply type it at the prompt.   The allowed colours are:

Black            White 
DarkBlue         Blue 
DarkGreen        Green 
DarkCyan         Cyan
DarkRed          Red 
DarkMagenta      Magenta  
DarkYellow       Yellow 
DarkGray         Gray

under: PowerShellV2