SimonS SimonS - 1 year ago 134
PowerShell Question

E-Mail body new line for each string

I have an array called

which contains filepath-strings.

To send them via
I have to merge them into a single string:

$bdy = $faultypath | Out-String

I send my E-Mail as HTML (
) is there a trick I can use to get every filepath in my
on a new line? Right now they're on the same line in the E-Mail.

if($faultypath) {
$utf8 = New-Object System.Text.utf8encoding
$bdy = $faultypath | Out-String
Send-MailMessage -From gdfgdfg `
-To dgdfgfdg `
-SmtpServer dgfgdfg `
-Subject "LogDeleter: Log-Pfad nicht gefunden" `
-Body "LogDeleter.ps1 konnte folgende Pfade nicht überprüfen:<br /><br />$bdy<br /><br />bitte aus LogDelete.ps1 löschen." `
-BodyAsHtml `
-Encoding $utf8

Answer Source

Use -join to combine the paths with a <br />. Then you have each path separated by a new line and don't need the Out-String anymore:

$bdy = $faultypath -join '<br />'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download