【发布时间】:2021-12-28 19:03:53
【问题描述】:
我希望下面的代码使用我的默认前景色打印详细文本:
$Host.PrivateData.VerboseForegroundColor = [console]::ForegroundColor
Write-Verbose 'Test' -Verbose
但是,它照常打印黄色文本。更改错误前景色 确实 工作:
$Host.PrivateData.ErrorForegroundColor = [console]::ForegroundColor
Write-Error 'test'
我发现绕过这个的唯一方法是这样做:
Write-Verbose 'Test' -Verbose *>&1 | Write-Host
但这并没有真正改变详细的颜色,它只是强制它使用 Write-Host 作为默认文本直接打印到控制台主机。我知道 Write-Host 确实可以让您将消息颜色更改为您想要的任何颜色,但这并不是一个理想的解决方案。
【问题讨论】:
-
$Host.PrivateData.VerboseForegroundColor = [console]::ForegroundColor.ToString()? -
嗯
(get-host).privatedata.verboseforegroundcolor = 'Gray'在 ps 5 中有效,但在 ps 7 中无效。使用$psstyle.Foreground.White不起作用。我的测试是echo hi > there; rm there -v -
@JosefZ 恐怕没什么区别。
标签: powershell colors powershell-core verbose