Monday, October 26, 2015

PowerShell color variable

I'd like to standardize the colors in my PowerShell script outputs.  So I need something like "WarningColor", "ErrorColor", "DebuggingColor", etc.

It turns out quite easy.  Below is an example.

$DebuggingColor = [System.ConsoleColor]::DarkGreen
$HighlightColor = [System.ConsoleColor]::Green
$WarningColor = [System.ConsoleColor]::Yellow
$ErrorColor = [System.ConsoleColor]::Red

Write-Host "hello world" -f $DebuggingColor


Reference:

https://leftlobed.wordpress.com/2008/05/31/setting-powershell-console-color-when-running-elevated/

No comments:

Post a Comment