I'm attempting to add color to characters in a string using Write-Host in a subexpression, but it only outputs to the beginning of the string.
For example:
"This is $(Write-Host 'failing to work' -ForegroundColor Yellow -NoNewline)"
Outputs:
failing to workThis is
My goal is to make it easily reusable with something like:
function color {
Write-Host $Args -ForegroundColor Yellow -NoNewline
}
"Add $(color 'to') strings"
EDIT
Thanks, lots of options there, but I don't see an explanation as to why $(Write-Host) behaves this way.