GoCD - How to display PowerShell output in color?

As the name says, how do we display console output from PowerShell scripts in color? We are using v16.12 GoCD.

Edit: due to company policy, we are not allowed to use write-host. Please do not ask why :)

+4
source share
3 answers

The answer is completely unrelated to GoCD. What about

[System.Console]::BackgroundColor="blue"
[System.Console]::ForegroundColor="yellow"
[System.Console]::WriteLine("yellow on blue");
0
source

If you need an easier way to handle these colors, you can install and use the TMOutput module, the module I wrote. It uses System.Console; however, it does this with less coding on your part.

: http://tommymaynard.com/script-sharing-write-output-gets-foreground-and-background-colors-and-more-2016/. Microsoft PowerShell. PowerShellGet, , .

Install-Module -Name TMOutput

: , , - reset , , , . , [System.Console] .

0

Write-Host, , .

$Host.UI.Write('Cyan','DarkMagenta','Text to display')

:

void Write(string value)
void Write(System.ConsoleColor foregroundColor, System.ConsoleColor backgroundColor, string value)

, , , PSScriptAnalyzer, Write-Host , Show (, Show-GoCDOutput), PSScriptAnalyzer .

0

Source: https://habr.com/ru/post/1671359/


All Articles