Monday, May 9, 2016

Remove Attachments Only From Exchange Server 2003/07/10/13 Using PowerShell

Most of the users of Exchange Server often encounters problem due to increasing size of mailbox database that can lead to high chances of corruption, longer access time and slower performance. Large-sized mailbox is mainly due to the presence of unnecessary attachments along with the emails in the mailbox. Several type of attachments present in the emails such as PDF, uncompressed image or zip archive may be very large consuming lots of the space in mailbox. In order to reduce the mailbox size, the blog will be discussing about the method to remove attachments only from Exchange Server 2003/2007/2010/2013 using PowerShell.

How to remove Attachments from Exchange Server

  • Exchange 2003

    For the Exchange Server 2003 version, we can use two methods for removing attachments that are as follows:
    1. Microsoft ExMerge Tool

    2. The tool developed by Microsoft is available free of cost on their official site. Following requirements needs to be met:
      1. Grant your user account full mailbox rights to all mailboxes you want to extract data from.
      2. Run the program on the machine with Exchange 2003 administrative tools installed.
      Install and launch the program. Click Next until you see Procedure Selection Option. Select Extract or Import and then click on Next to proceed. Specify the name of the server from which you want to remove messages with attachments. Go to Options for Data selection Criteria. In Data Tab-select User messages and folders, In Import Procedure Tab- Select Archive Data to Target Store, In Message Details tab, write the names of the attachments. Click OK and then Next. Select Mailboxes to start scanning. Select the folder destination where extracted messages need to be saved. Save the settings by choosing save settings option and click on Next to proceed. All the messages with specific attachments will be deleted.
      The disadvantages of this tool is it removes attachments along with messages and target PST File is saved in ANSI not UNICODE with limitation of 2GB size.
    3. Using PowerShell Command

      In order to use Export-Mailbox PowerShell command, execute it from the system having the following components installed: 32-bit version of the Exchange 2007 management tools and MS Outlook 2003 SP2 or later.
      The command will work successfully for specified mailboxes. User can use Get-Mailbox command to pipe its results to Export-Mailbox to include all mailboxes from the selected server. The following command will be used:
      Get-Mailbox | Export-Mailbox -AttachmentFilenames "*.PDF" -PSTFolderPath C:\Attach.pst –DeleteContent
      The command will remove all messages and the attachments from the database saving them in the local system.
  • Exchange 2007

    As stated in above section of Exchange 2003, the Export-Mailbox PowerShell command is used to extract messages with attachments from the database to reduce its size. Settings required to use this command are:
    1. A system with 32-bit version of Exchange 2007 management tools & MS Outlook 2003 SP2 or later installed.
    2. Users with Exchange Server Administrator Role and membership of local Administrators group.
    3. User needs to have access to all mailboxes.
    The same command that was used in Exchange 2003 will be used in Exchange 2007.
    Get-Mailbox | Export-Mailbox -AttachmentFilenames "*.PDF" -PSTFolderPath C:\Attach.pst –DeleteContent
    Running this command will remove all the messages with PDF attachments from the mailbox database and store them at the user’s system. The method removes not only attachments but also messages.
  • Exchange 2010/2013

    The PowerShell command used in Exchange 2010/2013 is New-MailboxExportRequest. In addition to this, for successful working of the command the system does not need to be 32-bit version of the Exchange management tools. Instead, user can launch it directly on Exchange 2010/2013 server. The only requirement is to grant the right to export mailboxes to particular user (administrator), which can be done by the following command:
    New-ManagementRoleAssignment –Role "Mailbox Import Export" –User Administrator
    Shared folder on selected folder needs to be created first and then Exchange Trusted Subsystem read/write permission needs to be granted. E.g. - Below command will use shared folder Share1 on SERVER1 machine:
    Get-Mailbox | New-MailboxExportRequest -ContentFilter {Attachment -like "*.PDF"} -FilePath "\\SERVER1\Share1\Attachments.pst"
    This command will copy all the messages with PDF type attachments to the Attachments.pst located at Share1 Folder on SERVER1 machine. Only difference between the New-MailboxExportRequest command and Export-Mailbox is it does not provide feature to remove attachments from database, which was available in Export-Mailbox command.


The blog has been aimed to helps user overcome the issue of increasing size of mailbox database due to attachments present in the Exchange Server that is no longer needed. The Microsoft has a free tool, ExMerge Tool that is used to remove attachments from the mailbox helping users reduce its size to some extent. However, the tool has disadvantages that it will save the PST file with ANSI format with 2GB limit. Blog further explains the Usage of PowerShell commands allowing user to save the attachments in UNICODE format PST file and commands may vary from one version to another version of Exchange Server.


Unknown said...

Your title says "Delete Attachments Only.." but -DeleteContent will delete the entire message AND the attachment. How do I only delete the attachment but leave the message intact?

Tej Pratap Shukla said...

Yes you are true, but you can modify the command according to your need. For example: don't write -DeleteContent in command, then all attachments will be exported to you local computer and then you can delete from you computer.
Yes I know that in the title I have written remove attachments only, but I wrote this by thinking about Exchange 2003/07/10/13.

Post a Comment

Post a reply