1
votes

Trying to extract email info like subject, senton, sender/receiver info etc. This is what i have so far :

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 <objects> | Export-CSV -NoTypeInformation  C:\.......\file_name.csv

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 ?

EDIT

The below code lists all the folders in mailbox :

$Name = $namespace.Folders.Item(1).Folders | FT Name

Is there a way to store each folder name one by 1 into $Name and use it to search in below code with a loop ?

$folder = $namespace.Folders.Item(1).Folders.Item("$Name").Items
1
I would look into Exchange Web Services (EWS): msdn.microsoft.com/EN-US/library/office/…Dane Boulton

1 Answers

0
votes

I'd suggest using the Find/FindNext or Restrict methods of the Items class to find items in the folder that correspond to your conditions. If you need to search in multiple folders you need to use the AdvancedSearch method of the Application class.

You can find the following articles helpful: