This script looks for specific emails in an exchange users mailbox, downloads the attachments, then marks those emails as read and moves the messages to a processed folder for archiving.
Outline
- Determines the Folder ID of the processed folder
- Finds the correct email messages based on defined search filters (e.g. unread, subject, has attachments)
- Copy's the attachments to the appropriate download location(s)
- Mark emails as read and move to the processed folder
Check out my Blog Post: Using Powershell and Microsoft EWS Managed API to download attachments in Exchange 2016
- Exchange 2007 or newer
- Exchange Web Services (EWS) Managed API 2.2
The processed folder is a subfolder of the root of the users mailbox (e.g. \\email@company.com\ProcessedFolder
). The root of a users mailbox is called the Top Information Store. If your processed folder is a subfolder under any other folder you must change $processedfolderpath
and $tftargetidroot
appropriately.
To quickly view the outlook folder location, right click on a folder in outlook, then click properties.
Example: processed folder is a subfolder of the root mailbox: Location: \\email@company.com\ProcessedFolder
$processedfolderpath = "/ProcessedFolder"
$tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$mailbox)
Example, processed folder is a subfolder of Inbox: Location: \\email@company.com\Inbox\ProcessedFolder
$processedfolderpath = "/Inbox/ProcessedFolder"
$tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$processedfolderpath)
- Create a Windows Service that will run the EWS Attachment Saver on an interval to check for applicable emails
-
Download the Microsoft Exchange Web Services Managed API 2.2 from
- Note, the original link was no longer valid. This now links to the download page on archive.org