Many a times Exchange users or administrators feel the need to read or go through certain emails via random Exchange user mailboxes of their choice. The need could be urgent on the basis of immediate information, action or in case, need for quick deletion of that particular email like phishing emails, emails with suspicious links, attachments and sensitive content. Seeking this need, an important aspect related to the Exchange users, we decided to create a help blog for them to fulfill this requirement of searching as well as deleting message from Exchange user mailboxes.
Searching & Deleting Exchange Mailboxes via Exchange Management Shell
This task of searching emails in the Exchange mailboxes can be achieved by the medium of Exchange Management Shell and thus this method applies to the Exchange Server 2010 to Exchange Server 2019 only.
In the Exchange Management Shell, the main cmdlet to search messages from Exchange user mailboxes is Search-Mailbox cmdlet.
Note: Exchange administrator must have assigned Mailbox Search management role which he can assign via Exchange Admin Center by visiting Discovery Management Role Group.
Administrators can use the Exchange Management Shell as well to assign these permissions with the following commands.
New-ManagementRoleAssignment -User <username> -Role “Mailbox Search”
Once the permissions are assigned, the Exchange Management Shell console must be restarted to make it in effects.
Using Search-Mailbox cmdlet in the Exchange Management Shell
It is advised that the user trying to perform this method should have some technical knowledge about how to work with Exchange Management shell beforehand to avoid time loss, confusions and big errors.
Now, let us start with the use of Search-Mailbox cmdlet in various ways to search and delete message in Exchange user mailboxes.
- Search emails defining attachments: This command holds the capability to list out all the emails containing common attachment file name. You just need to provide the attachment file name at the place bolded in the command along with the target folder name off already specified Exchange administrator (you can add other user mailbox and folder name also).
Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery attachment: filename –TargetMailbox administrator -TargetFolder “Folder name” –LogOnly -LogLevel Full
- Search emails defining words or phrases: If you have knowledge about the words or phrases used in the emails, then this command would surely help to extract all the emails from the specified user mailbox with those mentioned word or phrases in this command.
Search-Mailbox -Identity “enter user mailbox name” –SearchQuery Subject:”enter specific phrase or words” –TargetMailbox “enter target mailbox name”-TargetFolder “enter target folder name” –LogOnly -LogLevel Full
In the above command just replace the bolded words with name of the Exchange user mailbox, words or phrases common in emails, name of target mailbox to contain the search results and finally name of target folder respectively.
Now, you are familiar with the Search-Mailbox cmdlet and how to use it for searching the emails but if you want to search some specific emails and delete them after the search instantly, then also, we have brought you a help. The help is again in the form of cmdlets. Just check once here.
- Search and delete messages from the source mailbox: Run this command in the Exchange Management Shell, if you want to search specific emails to delete them directly from source rather than saving it to another location. Provide the required information in the following command (the bolded one) and run it to get the results.
Search-Mailbox -Identity “enter user mailbox name” –SearchQuery Subject:”enter specific phrase or words” –DeleteContent
Note: To search the emails based on Date and Time, the Search Query Subject can be replaced with Date or Time as per the requirement.
- Search, copy and delete messages from the source mailbox: If your intent is to move the searched mailboxes to another mailbox folder and delete it from the source mailbox simultaneously, then this command is for you.
Search-Mailbox -Identity “user mailbox name” –SearchQuery Subject:”enter specific phrase or words” –TargetMailbox “enter target mailbox name” –TargetFolder “enter target folder name” –LogLevel Full –DeleteContent
Provide the required details in the bold words in the above command as per your requirements.
- Search and delete emails from multiple mailboxes: For any reason, if you desire to delete emails based on certain subject from multiple mailboxes, then this command is for you.
Get-Mailbox -ResultSize Unlimited | Search-Mailbox -SearchQuery ‘Subject:”email subject”‘ -TargetMailbox “administrator” -TargetFolder “DeleteEmails” -LogOnly -DeleteContent
So, these were the commands which can serve you for search and deletion of the emails in the Exchange mailboxes but good practice and prior technical knowledge is always the requirement in this manual method as minor errors could result in complete failure and data loss situations.
Access Deleted, Inaccessible Exchange Server Emails
If your choice is different and you want it a quick and easy way to access desired Exchange mailbox messages (even the corrupted or deleted Exchange emails), then you should follow the path of the automated Exchange Recovery tool. It incorporates very simple Graphic User Interface keeping it easy-to-user for users and extracts all the content from the added source EDB file and with advanced filter options letting users to view selected emails content. Even you can move the selected data to various destinations including Microsoft 365, Outlook PST file or more as per your choice. At last, just go with our instinct and choose your way!
Summary
By running certain Exchange Management Shell cmdlets with the syntax Search-Mailbox, users can search emails within a specified mailbox on the basis of words, phrases, attachments, subject, etc. There are commands which can help you copy and delete the search messages as well. For that, you need to be the Exchange administrator and have technical adaptations to run the commands in the Exchange Management Shell. The advanced and automated third party toot to access the deleted or corrupted Exchange mailboxes emails is also provided.