title: Powershell: how to format Get-Childitem for email?
body: <p>Simply put, I'm trying to send an email from a Powershell script which lists the contents of a directory.</p>
  
  <p>In order to do this, I'm storing text in a variable, then inserting this variable into <code>Send-MailMessage</code>.</p>
  
  <p>My problem is this. When I pipe the object to <code>Out-String</code> as follows, it doesn't insert newlines:</p>
  
  <pre><code>$mailbody += "&lt;p&gt;" + (get-childitem $path | select-object Name | Out-String -width 40) + "&lt;/P&gt;"
  </code></pre>
  
  <p>Obviously, when <code>Get-Childitem</code> is entered at the prompt, the output is nicely formatted with newlines, however when stored to a variable then emailed (in an HTML email), there are no newlines, which results in an unreadable, long string of filenames.</p>
  
  <p>How do I do this?</p>