简体   繁体   English

有没有办法结合 -ForegroundColor 和 | 写主机语句中的外文件?

[英]Is there a way to combine -ForegroundColor and | Out-File in a Write-Host Statement?

I have some console outputs which also are logged in a txt file.我有一些控制台输出,它们也记录在 txt 文件中。

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.现在我希望此消息在 cmd 控制台上显示为红色。 So I tried this with -ForegroundColor but it did not work out:所以我用 -ForegroundColor 尝试了这个,但没有成功:

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.似乎 Out-File das 不像 -ForegroundColor 属性。

Is there a way to log console output which is also colored?有没有办法记录也是彩色的控制台输出?

I am using Write-Host without Out-File now but with Start Transcript at begin of my code.我现在正在使用没有 Out-File 的 Write-Host,但在我的代码开头使用 Start Transcript。 Working fine now.现在工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM