Simply put, I'm trying to send an email with a Powershell script that lists the contents of a directory.
To do this, I save the text in a variable, and then paste this variable into Send-MailMessage .
My problem is this. When I wrap an object on an Out-String as follows, it does not insert new lines:
$mailbody += "<p>" + (get-childitem $path | select-object Name | Out-String -width 40) + "</P>"
Obviously, when Get-Childitem is entered at Get-Childitem , the output is well formatted using newlines, however when saved in a variable then sent via email (in HTML email), there are no newlines, which results in an unreadable length of the name string files.
How to do it?
source share