Display a list (different line)when converting objects to string and send mail

Hi,

I have some objects stored in a variable and would like to use the select-object, do a format table and send them in an email.

 

I am managing to do this by converting them to a string, however the formatting of the string/email is a one liner.

 

How can I separate them to a different line? I want them to show , as when you do Format-Table for example.

 

This is what I am doing (In soon expiring there are multiple thing):

$body = $soonexpiring | Select-Object -Property samaccountname, @{label=‘Person Responsible’;expression={$_.manager -replace ‘^CN=|,.*$’}} | Format-Table | Out-String

send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high

 

How can this be done?

 

Thanks in advance! :slight_smile:

Format-Table is meant for formatting within the Powershell prompt. Try leveraging ConvertTo-HTML as you are already using the -BodyAsHtml switch:

$body = $soonexpiring |
Select-Object -Property samaccountname, @{label=‘Person Responsible’;expression={$_.manager -replace ‘^CN=|,.*$’}} |
ConvertTo-Html -As Table |
Out-String