Updated – Supports Exchange 2010/2013/2016 and Office365
There are many scenarios where we need to get rid of some Emails from the whole server
2.Confidential Email sent wrongly – Got to remove it
3. Need to remove a Email with Specific subject from all the mailboxes
Exchange 2010 has Good features on Searching it and Remove it .
So Will Learn how to do that.
For a User to Execute this commands , he needs specific permissions like he should be a member of Discovery Management role and he should be member of Mailbox Import Export
By Default, Administrator is not a member these roles
Use Exchange Management Shell
Replace the User Name with the Person whom you want to give access to Search and delete
Add-RoleGroupMember "Discovery Management" -Member "User Name"
You can use GUI or Shell, Adding the Discovery Management Role via GUI is much easier.
Login with the Exchange Control Panel URL below –
Login with Admin Credentials –
Double Click on Discovery Management and Add Administrator as a member of Discovery Management and Save it
To Add a User in Mailbox Import Export Role – Run in Exchange Management Shell
New-Managementroleassignment –Role "Mailbox Import Export" –User "Administrator"
Close and Reopen the Exchange Mangement Shell – so that the new commands will start working
Now Before Deleting in Bulk , We can use a log only switch to verify how many Mails we are going to delete
and to verify the we are going to delete the right one
Get-mailbox | search-mailbox –searchquery "Subject:'virus'" –Logonly –Targetmailbox administrator –Targetfolder Inbox
Now this will show how many mailboxes have this content
A mail will be generated to Administrators inbox with Item Count As shown below —
Now we will go ahead and delete it
Get-mailbox | search-mailbox –searchquery "Subject:'virus'" –DeleteContent
Before — From All the Mailboxes
Now its gone from All the mailboxes
Reference link –
Hope it helped you to understand better !!
If you feel its too confusing – Check out the Automated Script to do these tasks for you