Created
July 18, 2017 07:48
-
-
Save Sam-Martin/9e515c9935c62de77c3377f27b5520ec to your computer and use it in GitHub Desktop.
PowerShell Coloured output (stolen from someone somewhere)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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