title: Get contents of msg file into string
body: <p>I am using Powershell to parse the contents of email messages that are saved to a local folder.</p>
  
  <p>The code is as follows...</p>
  
  <pre><code>Get-ChildItem "C:\projtest\emails" -Filter *.msg |
  ForEach-Object {
      $msg = ""
      $outlook = New-Object -comobject outlook.application
      $msg = $outlook.Session.OpenSharedItem($_.FullName)
      $msg | Select -ExpandProperty body 
  
      Write-Host $msg
  }
  
  $outlook.Quit()
  </code></pre>
  
  <p>For now, I just want to open the file, get the contents, and display it.</p>
  
  <p>The issue I'm running into is that once the script is run, OUTLOOK.EXE does not close so I cannot run the script again on the same message.</p>
  
  <p>Is there a better way to open Outlook e-mail messages, get the contents into a string in PowerShell, and close the Outlook process?</p>