#Changing Color of Grid Text based on Output

1 messages · Page 1 of 1 (latest)

visual gulch
#

I stumbled across this screenshot and was just curious how they've managed to make Online "False" red and "True" green?

The only way I am aware of doing this is by using Dotnet objects like [System.Console]::ForegroundColor but then this would mean the output isn't a typical PowerShell output, but rather a giant string.

I noticed aswell the sorting is hard-coded into the .ps1 file and not piped so maybe that's hte case but I just wanted to check I hadn't missed a trick?

twilit void
#

You can either add it to the property (bad if you want to use it for something) or set a pstypename on the psco and add formatting.

The best way is to do it with formatting as that doesnt change the object only the presentation.

You can use $PSStyle for easy access to the VT codes or if you want more options the module Pansies is pretty nice

The module EZOut makes it pretty easy to add your own formats.

#
'{0}{1}First - {2}{3}Second - {4}{5}{6}Bold' -f $PSStyle.Foreground.Red, $PSStyle.Background.Green, $PSStyle.Foreground.Green, $psstyle.Background.Red, $PSStyle.Blink, $PSStyle.Background.Yellow, $PSStyle.Foreground.BrightCyan

Example

visual gulch
#

Thanks, I hadn't heard of any of these. Just read up a bit on PSStyles and I can see it can be used for errors etc, is there anyway to change the text by a regex or anything? Or is just whether it's an error or as you write to the terminal?

twilit void
compact agate