Home > database >  CRLF using powershell write-host
CRLF using powershell write-host

Time:12-14

I am trying to output a log file to a variable and use that variable as Body on a Send-MailMessage. The problem is that all CRLFs in the variable are missing in the output.

ex.

$Body = get-content .\TTT.txt
$body
Test
Test1
Test2

write-host "$($Body)"
Test Test1 Test2

Is there a way to avoid it? (keep the CRLF)

CodePudding user response:

Documentation gives an answer:

When writing a collection to the host, elements of the collection are printed on the same line separated by a single space. This can be overridden with the Separator parameter.

Write-Host docs

CodePudding user response:

If you must use Write-Host then add the parameter -Separator with Newline:

Write-Host $Body -Separator "`n"
  • Related