carriage return string email body in foreach loop

I can’t get this to happen. I like to get every new line with linebreak but it will not work.

The mail is sent as it should but not in body as i like it to be.

[string]$emailbody = ""
$process = Get-Process

foreach($proc in $process){

    $emailbody = $emailbody + $proc + "`r`n"
$cred = [pscredential]::new("",(ConvertTo-SecureString -String "Password" -AsPlainText -Force))
Send-MailMessage -To -from -Subject 'test' -Body $emailbody -BodyAsHtml -smtpserver -usessl -Credential $cred -Port 587

What are you expecting in your output? Are you trying to see all of the properties in Get-Process? You would need to do something like this to get a carriage return in the email.

“$emailbody $proc `r`n” or $emailbody + “$proc`r`n”


Many thanks :slight_smile:
I knew it was someting simple that I was missing.

The help are as folows.

[string]$emailbody = ""
$process = Get-Process -ProcessName WUDFHost

foreach($proc in $process){

$emailbody = $emailbody + $proc

$cred = [pscredential]::new("",(ConvertTo-SecureString -String "Password!" -AsPlainText -Force))
Send-MailMessage -To -from -Subject 'test' -Body "$emailbody $proc`r`n" -BodyAsHtml -smtpserver -usessl -Credential $cred -Port 587