How to remove attachments from Exchange mailbox database to reduce its size

[Update]: This post was updated on August 11, 2016.

Every MS Exchange administrator faces this problem at some point – growing mailbox database due to a plethora of attachments saved together with emails in it. Why is this an issue? Bigger database file means bigger chance of corruption, longer access times and obviously the necessity of HDD storage expansion. In email correspondence the message itself is just a couple hundred of kilobytes. But when it contains e.g. a PDF attachment, uncompressed image or zip archive, its size might be even tenfold bigger. With hundreds of emails received every day one can only imagine at what mad rate a free space of Exchange server is shrinking. There are different ways of handling this problem, depending on Exchange server version installed.

Exchange 2003

There are two ways of extracting attachments from the mailstore database:

1.The ExMerge tool

The tool is provided by Microsoft free of charge and available on their general download site. To use it you need to meet following requirements:

  • grant your user account full mailbox rights to all mailboxes you want to extract data from,
  • run the program on the machine with the Exchange 2003 administrative tools installed. You can run the tool directly on Exchange 2003, however it is not recommended.

After launching the program a wizard is shown. Click Next until you see Procedure Selection step. Select Extract or Import (Two Step Procedure) then click Next. On the following screen specify the name of the server, from which you want to remove messages with attachments. Click Options to specify extraction criteria:

  • in Data tab select User messages and foldersExMerge Data Selection Criteria - Data
  • in Import Procedure select Archive Data to Target Store (this removes selected messages from the database)ExMerge Data Selection Criteria - Import Procedure
  • in Message Details tab specify the name of the attachment (e.g. *.pdf)ExMerge Data Selection Criteria - Message Details

Click OK, then hit Next. In the following window select mailboxes you want to process. Click Select All to scan all of them. After clicking the Next button the Locale window is shown – select the locale of your choice. Next screen allows selection of the folder path, where extracted messages are saved in PST file. Click Next. Now save all your settings by clicking the Save Settings button. After you hit Next the process starts – depending on the size of the mailbox database it might take considerable amount of time. When it finishes, all messages containing specified attachments are deleted from database and stored in the PST file. While the method is quite effective and cost-free there are two cons to be aware of:

  • The tool removes whole messages, not just their attachments.
  • The target PST file is saved in the ANSI coding limiting its size to up to 2GB

2. Export-Mailbox Powershell command.

To use it you need to run it from the machine that has the following components installed:

  • The 32-bit version of the Exchange 2007 management tools
  • MS Outlook 2003 SP2 or later.

Note that you can use this method against Exchange 2003 SP2 only. Since the very same command is used to extract data from the Exchange 2007 server too, go to the next section to learn detailed usage description.

Exchange 2007

As mentioned in the previous section, the Export-Mailbox Powershell command can be used to extract messages with attachments from the mailstore database to reduce its size. Following setup is required to successfully use it:

  • A computer with the 32-bit version of the Exchange 2007 management tools and MS Outlook 2003 SP2 or later installed
  • User with Exchange Server Administrator Role and membership of the local Administrators group
  • User must have full access to all mailboxes

The command works for specified mailboxes, therefore it is easier to use the Get-Mailbox command and pipe its results to Export-Mailbox to include all mailboxes from the selected server. Full syntax of the command is:

Get-Mailbox | Export-Mailbox -AttachmentFilenames "*.PDF" -PSTFolderPath C:\Attach.pst –DeleteContent

After running the above command all messages with PDF attachments are removed from the database and saved in the Attach.pst file on the C: drive. Similar to the ExMerge tool used for Exchange 2003, this method does not leave messages in the database, but removes them completely.

Exchange 2010/2013/2016

To reduce the oversized mailbox database the administrator can use the Powershell command as well. Its name is now New-MailboxExportRequest. Additionally it does not require to be executed on the machine with 32bit version of the Exchange management tools – you can launch it directly on the Exchange 2010/2013/2016 server. The only requirement is to grant the right to export mailboxes to the specific user (Administrator). You can perform this with the following PS command:

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User Administrator

Additionally you need to create shared folder on selected server and grant Exchange Trusted Subsystem read/write permission to it. In the example below the folder PSTShare on the SERVER01 machine is used, The full syntax of the attachment export command is:

Get-Mailbox | New-MailboxExportRequest -ContentFilter {Attachment -like "*.PDF"} -FilePath "\\SERVER01\PSTShare\Attachments.pst"

The result is similar to the previous commands – all messages with the PDF type file in them are copied to the Attachments.PST located in the PSTShare shared folder. The difference is that the New-MailboxExportRequest command does not provide removal functionality, with –DeleteContent switch, which was available in the Export-Mailbox cmdlet.


Microsoft has presented a different approach to the data exporting from the mailstore database across different versions of Exchange. From wizard-like tools for the 2003 version to script-only and quite limited in actions available in one step on 2010/2013/2016 Exchange. Despite the fact the native tools are provided, the issue of attachments stripping seems to be half addressed. None of the methods above would do the perfect thing – remove attachment files and leave messages in the store. Features such as adding the link to the message, which would guide to the location of the stripped attachment or creating automatically a different store in Exchange for attachment files are still just a dream of the sysadmin.

Suggested reading

Managing User Mailboxes (Exchange 2007)
Manage user mailboxes (Exchange 2013)
CodeTwo Exchange Rules Pro: Delete, archive and dump Exchange email attachments on the go

Tools for Microsoft 365

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


CodeTwo sp. z o.o. sp. k. is a controller of your personal data.
See our Privacy Policy to learn more.