Skip to content
A Powershell script that 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.
PowerShell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
EWSEmailAttachmentSaver.ps1 First commit Mar 9, 2019
LICENSE Initial commit Mar 9, 2019
README.md First commit Mar 9, 2019

README.md

EWS Email Attachment Saver

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

  1. Determines the Folder ID of the processed folder
  2. Finds the correct email messages based on defined search filters (e.g. unread, subject, has attachments)
  3. Copy's the attachments to the appropriate download location(s)
  4. 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

Requirements

  • Exchange 2007 or newer
  • Exchange Web Services (EWS) Managed API 2.2

Additional Information

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)

Future Enhancements

  • Create a Windows Service that will run the EWS Attachment Saver on an interval to check for applicable emails

Credits/Resources

You can’t perform that action at this time.