79776442

Date: 2025-09-26 22:58:26
Score: 1
Natty:
Report link

For a Write-Host to console, I want to colorize a word in my log, e.g.

Write-Color 'How', '', 'now', 'Yellow', 'brown cow?'

function Write-Color {
    param(
        [string[]]# text+color pairs
        $ss
        )
    for ($i = 0; $i -lt $ss.Count; $i++) {
        $s = $ss[$i++]
        $c = $ss[$i]
        if ($c -eq $null -or $c -eq "") {
            Write-Host "$s " -NoNewLine
        } else {
            Write-Host "$s " -ForegroundColor $c -NoNewLine
        }
    }
    Write-Host ""
}
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Andre