title: PowerShell - Extract email information From Outlook
body: <p>Trying to extract email info like subject, senton, sender/receiver info etc.
  This is what i have so far : </p>
  
  <pre><code>Add-type -assembly "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)
  $Mail = $folder.items | where-object { conditions }
  $Mail | Select-Object -Property &lt;objects&gt; | Export-CSV -NoTypeInformation  C:\.......\file_name.csv
  </code></pre>
  
  <p>This code only checks for the mails in the Inbox folder, cause of setting in 5th line of code. Is there any way to run from root directory ? So, it can parse all the folders like draft, sentitems and deleted items? Also, any way to list from which exact folder this mail was in and add it to the excel file ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The below code lists all the folders in mailbox :</p>
  
  <p><code>$Name = $namespace.Folders.Item(1).Folders | FT Name</code></p>
  
  <p>Is there a way to store each folder name one by 1 into <code>$Name</code> and use it to search in below code with a loop ?</p>
  
  <pre><code>$folder = $namespace.Folders.Item(1).Folders.Item("$Name").Items
  </code></pre>