Skip to content

Instantly share code, notes, and snippets.

@Sam-Martin
Created July 18, 2017 07:48
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 Sam-Martin/9e515c9935c62de77c3377f27b5520ec to your computer and use it in GitHub Desktop.
Save Sam-Martin/9e515c9935c62de77c3377f27b5520ec to your computer and use it in GitHub Desktop.
PowerShell Coloured output (stolen from someone somewhere)
function Format-AnsiColor {
[CmdletBinding()]
[OutputType([String])]
param(
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[AllowEmptyString()]
[String]
$Message,
[Parameter(Mandatory=$True)]
[ValidateSet(
'black'
,'red'
,'green'
,'yellow'
,'blue'
,'magenta'
,'cyan'
,'white'
)]
[String]
$ForegroundColor
)
Begin {
$e = [char]27
$fore = (Get-Variable "ForegroundColor").Attributes.ValidValues | % {$i=0} {@{$_=$i+30};$i++}
}
Process {
"$e[$($fore.$ForegroundColor)m$Message"
}
}
'One','Two','Three' | Format-AnsiColor -ForegroundColor red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment