Como no meu exemplo abaixo, você pode tentar corresponder sua saída e colorir de acordo.
$Items = @("Find","Matching","Item")
$colItem = "Matching"
foreach ($i in $Items) {
if ($i -match $colItem){
write-host $i -foregroundcolor magenta -BackgroundColor yellow}
else {write-host $i}
}
- Editar -
Continue com um exemplo prático de trabalho (verificado apenas com o ps4) "grepping" da saída do cmdlet Get Help para o Phrase PowerShell.
Function Coloured-Output {
Process {
$i = "PowerShell"
If ($_ -match $i){
$iPosition = $_.IndexOf($i) # start position of "grep phrase"
$iLength = $i.Length # length of grep phrase
$iEnd = $iPosition + $iLength # end of grep phrase
$LineLength = $_.Length # length of line
$iComplete = $LineLength - $iEnd # length of characters to complete the line
Write-Host $_.Substring(0,$iPosition) -NoNewline
Write-Host $_.Substring($iPosition,$iLength) -Foregroundcolor Blue -BackgroundColor cyan -NoNewline
Write-Host $_.Substring($iEnd,$iComplete)
} # End of IF
else {write-host $_ }
} # End of Process
} # End of Function
Get-Help | Out-String -stream | Coloured-Output