Remove specific messages from Exchange 2010 Server

 

Sometimes Exchange administrator need to remove messages that fit specific criteria from large number of mailboxes or from Exchange transport queues.

Removing messages from Exchange mailboxes:

To perform remove message operation from mailboxes, in Exchange 2010 RBAC Mailbox Export Import role must be assigned to the admin account. To remove messages from Exchange 2010 mailboxes we will use Search-Mailbox cmdlet.

Account used to export data from mailboxes must be:

  • an Exchange Server Administrator
  • member of local Administrators group of target server
  • Full Access permission assigned to the mailboxes

 

To add RBAC role to user Admin:

New-ManagementRoleAssignment –Role “Mailbox Import Export” –User “Admin”

 

Sometimes you will need to add necessary permissions for user Admin to all mailboxes, then we can use:

Get-Mailbox -ResultSize unlimited | Add-MailboxPermissions -User Admin -AccessRights FullAccess -InheritanceType all

After completed removing operations, we have to remove this permissions like below:

Get-Mailbox -ResultSize unlimited |Remove-MailboxPermissions -User Admin -AccessRights FullAccess -InheritanceType all

 

To search all messages with specified subject like “Important Message” of all mailboxes on server MBX1 we have to use example like below:

Get-Mailbox -Server  "MBX1" -ResultSize Unlimited | Search-Mailbox -SearchQuery 'Subject:"*Important Message*" -targetmailbox "*SearchMailbox*" -targetfolder "*SearchFolder*" -logonly -loglevel full

Continue reading