Email this to a friend
 
posted on March 12th 2018, at 08:27
by lunarg

Starting from Windows 10 Creators Fall Update, you can use VT escape sequences to colorize the output to console. You can use this to colorize columns in Format-Table, too.

A sample snippet, colorizing the output based on the contents of the "Status" field:

$somelist | FT FirstName,LastName,@{l="Status";e={
    switch ($_.Status) {
        "OK" {$color = 92; break}
        "NOT OK" {$color = 91; break}
        default {$color = 93}
    }
    "$e[${color}m$($_.Status)${e}[0m"
}}

A complete list of color codes can be found here: https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

Send a link to this post to yourself or a friend.

Send to e-mail:
Your name:
Your e-mail:
Captcha:
Type the letters and numbers as shown.
/get/captcha/1711725598
Not readable? Get another.
 
Information entered is solely used for sending a one-time e-mail, and is not retained and/or passed on to a third party.
 
 
 
 
« March 2024»
SunMonTueWedThuFriSat
     12
3456789
10111213141516
17181920212223
24252627282930
31      
 
Links
 
Quote
« Debating Windows vs. Linux vs. Mac is pointless: they all have their merits and flaws, and it ultimately comes to down to personal preference. »
Me