powershell sends an echo output to an email

You need to read the contents of the log file and use that for the Body parameter

# -Raw reads it as single multiline string, including newlines
$body = Get-Content -Path 'C:\log.log' -Raw  
Send-MailMessage -Body $body ...

If the mail is to be HTML (with switch -BodyAsHtml), you need to convert the newlines to <br /> like

# without -Raw you get the content as string array
$body = (Get-Content -Path 'C:\log.log') -join '<br />'
Send-MailMessage -Body $body -BodyAsHtml ...

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top