title: How do I remove all newlines from a string in PowerShell?
body: <p>This is the code I am using to parse my emails. If they match a specific date, I want to add them to a list of other emails, then make that into a flat file:</p>
  
  <pre><code>outfile = "C:\Temp\emails.csv"
  $olFolderInbox = 6
  $ol = new-object -comobject "Outlook.Application"
  $mapi = $ol.getnamespace("mapi")
  $inbox = $mapi.GetDefaultFolder($olFolderInbox)
  $msgs = $inbox.Folders.Item("root")
  $list1 = @()
  foreach($message in ($msgs.items))
  {
      if($message.ReceivedTime -gt $(get-date).adddays(-14))
      {
          $list1 += "$($message.Subject);$($message.ReceivedTime);$($message.Body.Replace("`n",", "))"
      }
  }
  if(Test-Path $outfile)
  {
      Remove-Item $outfile
      Add-Content $outfile $list1
  }
  else
  {
      Add-Content $outfile $list1
  }
  </code></pre>
  
  <p>The problem I run into is that the replace statement on <code>$message.Body.Replace("`n",", ")</code> doesn't actually remove newlines, and the file doesn't get created appropriately. Is there a way to confirm that the entire contents of the body portion become a single line?</p>
  
  <p>I have confirmed that the <code>$message.body</code> object is a string, so I'm not certain why this is not working.</p>