title: powershell script to export all outlook emails from folders/subfolders to csv file
body: <p>I need to export all emails from a shared Outlook inbox. The emails are sorted into sub-folders.</p>
  
  <p>I've tried running a PowerShell function in the command window. </p>
  
  <pre><code>Function Get-OutlookInBox {
      Add-Type -AssemblyName "Microsoft.Office.Interop.Outlook" | Out-Null
      $olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
      $Outlook = New-Object -ComObject Outlook.Application
      $Namespace = $Outlook.GetNameSpace("MAPI")
      $Folder = $Namespace.GetDefaultFolder($olFolders::olFolderInBox)
      $Folder.Items |
          Select-Object -Property Subject, ReceivedTime, SenderName,
              SenderEmailAddress |
          Export-Csv -NoTypeInformation XXXX\Trial.csv
  }
  </code></pre>
  
  <p>Does not generate a CSV file.</p>