Invoke-ColorOutput

Born out of the need to avoid write-host, but still wanting pretty colors, Invoke-ColorOutput was born! This function allows you to write output to the screen in a beautiful colorized way, and not have to worry about killing puppies…

Github: https://github.com/Toasterlabs/PSCommon/blob/master/Public/Logging%20and%20Console/invoke-coloroutput.ps1

Parameters

Object

Aliases: Message, msg
This is the meat of the function, the text we want to display.

Foregroundcolor

Aliases: Fore, FGR
Defines what color our text should be. Currently only accepts the default values available in PowerShell: ‘Black’, ‘DarkBlue’, ‘DarkGreen’, ‘DarkCyan’, ‘DarkRed’, ‘DarkMagenta’, ‘DarkYellow’, ‘Gray’, ‘DarkGray’, ‘Blue’, ‘Green’, ‘Cyan’, ‘Red’, ‘Magenta’, ‘Yellow’, ‘White’

BackgroundColor

Aliases: Back, BGR
Defines what color the console should put in the background. Currently only accepts the default values available in PowerShell: ‘Black’, ‘DarkBlue’, ‘DarkGreen’, ‘DarkCyan’, ‘DarkRed’, ‘DarkMagenta’, ‘DarkYellow’, ‘Gray’, ‘DarkGray’, ‘Blue’, ‘Green’, ‘Cyan’, ‘Red’, ‘Magenta’, ‘Yellow’, ‘White.

Examples

Invoke-ColorOutput -Message ‘Just a test message’

Writes a simple message to the console:

1..10 | Invoke-ColorOutput

Writes 1 to 10 on the console:

Invoke-ColorOutput -Message ‘Just a test message’ -foregroundcolor “Green”

Write a message in a green color to the console:


Invoke-ColorOutput -Message ‘Just a test message’ -foregroundcolor White -BackgroundColor Red

Writes a message in white text on a red background:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Menu
%d bloggers like this: