Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use -Format Operator in Write-Host or Write-Debug?

Do i miss something or is it not possible to get my formatting in a Write-Debug statement?

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

Write-Debug "Date: {0:d}" -f (Get-Date) #Does not work
like image 266
icnivad Avatar asked Apr 21 '11 19:04

icnivad


1 Answers

Try changing $DebugPreference to "continue" and add some parens:

$DebugPreference = "Continue"

Write-Debug ("Date: {0:d}" -f (Get-Date))

The default for $DebugPreference is "SilentlyContinue" so Write-Debug won't display anything.

Write-Host will just work if you enclose your message in the parens.

like image 183
Greg Wojan Avatar answered Oct 17 '22 08:10

Greg Wojan