skoeld
April 4, 2019, 6:15am
1
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("mail@domain.com",(ConvertTo-SecureString -String "Password" -AsPlainText -Force))
Send-MailMessage -To mail@domain.com -from mail@domain.com -Subject 'test' -Body $emailbody -BodyAsHtml -smtpserver smtp.office365.com -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”
pwshliquori
skoeld
April 4, 2019, 7:04am
3
Many thanks
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("mail@domain.com",(ConvertTo-SecureString -String "Password!" -AsPlainText -Force))
Send-MailMessage -To mail@domain.com -from mail@domain.com -Subject 'test' -Body "$emailbody $proc`r`n" -BodyAsHtml -smtpserver smtp.office365.com -usessl -Credential $cred -Port 587