Powershell EMail: How to add new line in email Body? Powershell EMail: How to add new line in email Body? powershell powershell

Powershell EMail: How to add new line in email Body?


(From my comment)

The PowerShell newline indicator is `n (backtick-n), so:

$Body = "Server Name:  $server, <NEED NEW LINE> Drive: C

becomes:

$Body = "Server Name:  $server, `n Drive: C


I'm not sure how these other users were able to make the `n create a new line but I never could get it to work...

Instead I ended up doing the following...

  • Using the -BodyAsHtml switch
  • Using the <br /> (break) html tag

For example...

powershell -ExecutionPolicy ByPass -Command Send-MailMessage -BodyAsHtml -SmtpServer 'myemail.server.com' -To 'Mr To <to@server.com>' -From 'Mr From <from@server.com>' -Subject 'Reports From Daily SQL Backup Jobs' -Body 'There was an issue backing up the databases and sending them to the virtual drive.<br />Test Line 2.<br />Test Line 3.-more on line 3<br />Test Line 4.<br />EOF<br />'"


Just putting it in your script the way you want it to appear worked for me, although I am on version 4.0. Not sure what version you were on or if that makes a difference.

$Body = "Server Name:  $serverDrive: CTotal Size: $sizeGBSpace Left: $freeSpaceGB"