PowerShell - подкраска текста

Для этого используются в комндлетах вывода аргументы, типа ForegroundColor или BackgroundColor, я для себя написал небольшие обертки для разного рода сообщений - info, error, warning, notice, regular:

# Messages
function errorMsg
{
    param
    ([Parameter(Mandatory = $true)]$msg)
    Write-Host - $msg -ForegroundColor Red -NoNewline; $countError++; writeLog -msg "$msg" -Severity Error
}
function infoMsg
{
    param
    ([Parameter(Mandatory = $true)]$msg)
    Write-Host - $msg -ForegroundColor Green -NoNewline;
}
function warningMsg
{
    param
    ([Parameter(Mandatory = $true)]$msg)
    Write-Host $msg  -ForegroundColor Red -BackgroundColor Yellow -NoNewline; writeLog -msg "$msg" -Severity Warning
}
function regularMsg
{
    param
    ([Parameter(Mandatory = $true)]$msg)
    Write-Host $msg -ForegroundColor White -NoNewline;
}
function noticeMsg
{
    param
    ([Parameter(Mandatory = $true)]$msg)
    Write-Host - $msg -ForegroundColor Magenta -NoNewline;
}

Использовать в коде можно так:

regularMsg -msg "This is "
errorMsg -msg "Error`n"

regularMsg -msg "My blog is "
infoMsg -msg "Sys-Adm.in`n"

regularMsg -msg "Our forum is "
warningMsg -msg "forum.sys-adm.in`n"

regularMsg -msg "Sys-Admin Channel "
noticeMsg -msg "https://t.me/sysadm_in_channel"

Результат:

image

up
Нашелся прикольный пример:

function Test-Output {
    Write-Output "Hello World"
}

function Test-Output2 {
    Write-Host "Hello World" -foreground Green
}

function Receive-Output {
    process { Write-Host $_ -foreground Yellow }
}

#Output piped to another function, not displayed in first.
Test-Output | Receive-Output

#Output not piped to 2nd function, only displayed in first.
Test-Output2 | Receive-Output 

#Pipeline sends to Out-Default at the end.
Test-Output 

image