我可以在Write-Host或Write-Debug中使用-Format运算符吗?

时间:2011-04-21 19:41:30

标签: powershell format

我是否遗漏了某些内容,或者是否无法在Write-Debug语句中获取格式?

"Date: {0:d}" -f (Get-Date) #Works as expected

Write-Debug "Date: {0:d}" -f (Get-Date) #Does not work

1 个答案:

答案 0 :(得分:9)

尝试将$ DebugPreference更改为“continue”并添加一些parens:

$ DebugPreference =“继续”

写入调试(“日期:{0:d}” - f(获取日期))

$ DebugPreference的默认值是“SilentlyContinue”,因此Write-Debug不会显示任何内容。

如果您将邮件附在parens中,则写入主机将正常工作。