Export-Mailbox is no longer supported in Exchange 2010 sp1, in stead there is New-MailboxExportRequest but the problem is that “-DeleteContents” is not supported with mailbox export.
In order to be able to search and delete emails from multiple Exchange 2010 mailboxes one has to have the following roles assigned.
New-ManagementRoleAssignment -Role "Support Diagnostics" –User username
New- ManagementRoleAssignment -Role "Mailbox Import Export" -User username
above will ensure that a user has proper permissions to perform this command.
In order to find and delete a certain email from one mailbox you can perform the following command
Search-Mailbox -Identity username -SearchQuery 'subject:"Email Subject that you want to search for"' –DeleteContent
this can be run for all mailboxes on a server as well
Get-Mailbox –Server “*servername*” –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:"Email Subject that you want to search for"' –DeleteContent
For working out troubles related to corrupted or lost edb files you may use EDB recover, which allowing to work under all Windows OS and with all versions of MS Exchange Server. It uses all modern methods of restoring data.
ReplyDeleteWhen I attempt the Get-Mailbox –Server “*servername*” –ResultSize unlimited | Search-Mailbox -SearchQuery 'subject:"Email Subject that you want to search for"' –DeleteContent command, all I get is a >> prompt.
ReplyDeleteyou are missing a ' at the end.
DeleteTry server name withou ""
ReplyDeleteThe prompt means that your command is not completed
Thanks, got a rogue mail fixed with this and another resource.
ReplyDeletehttp://www.techieshelp.com/delete-mail-from-multiple-mailboxes/
This is great, been looking for it. However, i am having problem with running shell cammand. Following is result, HELP PLEASE
ReplyDeleteThe term 'Search-Mailbox' is not recognized as the name of a cmdlet, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:69
* Get-Mailbox -Server "****" -ResultSize unlimited | Search-Mailbox <<<< -SearchQuery 'Subject:"test email"' -DeleteContent
+CategoryInfo : ObjectNotFound: [], CommandNotFoundException
= FullyQualifiedErrorId : CommandNotFoundException
I recommend that first you run the command without -DeleteContents. Add -LogLevel Full -TargetMailbox "My Name" -TargetFolder "a mailbox folder name for this"
ReplyDeleteWhen done, it will put an email in your target folder with a CSV attachment with the results. You can then make sure you are only deleting what you want.
Also add other parameters to the searchQuery to make sure you get it right: -SearchQuery 'subject:"the bad email subject" sent:today from:"name of person who goofed"'
Once you verify that you will only be deleting the emails you expect, run the same command and add the -DeleteContents switch. The resulting csv in your mailbox is the log record of what happened.
Dear Jeffrey,
DeleteThank you for a very valid suggestion.
Thanks Bhojraj,this helped us get rid of an email a naughty student sent around school. We had to enable the command first, I referenced http://www.techieshelp.com/delete-mail-from-multiple-mailboxes/ for anyone who has the same issue
ReplyDelete