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