0

I have some console outputs which also are logged in a txt file.

Write-Host "$Time : $file failed/skipped. Technical information: $ExceptionMessage" | Out-file -FilePath $logPath -Append

Now I want that this message appears in red on the cmd console. So I tried this with -ForegroundColor but it did not work out:

Write-Host "$Time : $file failed/skipped. Technical information: $ExceptionMessage" -ForegroundColor Red | Out-file -FilePath $logPath -Append

It seems like Out-File das not like the -ForegroundColor property.

Is there a way to log console output which is also colored?

Mensur
  • 3
  • 2
  • Pretty sure that Write-Host "anytext" | Out-File won't work without colour either - Write-Host sends the text to the host - it is then lost – Scepticalist Dec 06 '19 at 10:30
  • You can also consider using [ANSI codes](https://stackoverflow.com/questions/51680709/colored-text-output-in-powershell-console-using-ansi-vt100-codes) embedded in your string to colorize the output. – Rich Moss Dec 06 '19 at 16:06

1 Answers1

0

I am using Write-Host without Out-File now but with Start Transcript at begin of my code. Working fine now.

Mensur
  • 3
  • 2