Kernel Data Recovery Blog

Search & delete messages from Exchange user mailboxes with Search-Mailbox command

Read time: 5 minutes

Summary: The Exchange Management Shell offers robust control over Exchange environments, enabling efficient mailbox and database management. Learn how to use the Search-Mailbox command for searching and deleting messages, essential for safeguarding sensitive data. Assign specific roles, use cmdlets, and follow step-by-step instructions for effective mailbox management. Discover Kernel for Exchange Recovery tool for precise email searches, previews, and recovery in various environments. Ultimately, this article emphasizes the importance of mastering Exchange Management Shell for seamless email management and data retrieval on Exchange Servers.

The Exchange Management Shell empowers administrators with robust control over their Exchange environment. It not only allows you to efficiently search mailbox and database details but also execute various essential actions. While it may not offer the same user-friendly experience as the Exchange admin center, it excels in performing a broader range of tasks with greater comprehensiveness. In this discussion, we will explore the utilization of the Search-Mailbox command to search for and delete messages from Exchange user mailboxes.

Why do you need to search and delete messages?

Email exchanges often contain a wealth of critical and sensitive information, making it imperative to prevent unauthorized access. The repercussions of such information falling into the wrong hands can lead to significant financial losses and reputation damage. In cases where emails have been mistakenly sent to unintended recipients, administrators possess the capability to locate and remove them swiftly through the utilization of the Search-Mailbox command.

How to search & delete messages from Exchange user mailboxes?

Here is how you can Search & Delete Messages from Exchange User Mailboxes using Exchange Management Shell cmdlets.

To check the contents of a mailboxes, the command is Search-Mailbox.
Other than searching specific items in a mailbox, the following tasks can also be performed using this cmdlet:

Requirements for using the cmdlet

Before Starting, be Sure That:

How to search mailboxes and delete messages?

The primary requirement is assigning two management roles to the account via Exchange Management Shell or Exchange Admin Center.

Let us see how to run the cmdlet

To start with, run the Exchange Management Shell application as an administrator.

The below cmdlet is for searching specific message(s) in the user mailboxes. Just provide your mailbox name and specific phrase or words, and the target folder name where you want to save the data.

Search-Mailbox -Identity “user mailbox name” –SearchQuery Subject:”specific phrase or words” –TargetMailbox “target mailbox name”-TargetFolder “target folder name” –LogOnly -LogLevel Full

For Example:

Now, let us see how to search messages using the SearchQuery of attachment parameter in all the mailboxes.

Get-Mailbox -ResultSize unlimited | Search-Mailbox -SearchQuery attachment: filename –TargetMailbox administrator -TargetFolder “Folder name” –LogOnly -LogLevel Full

The output result would be all the messages containing that attachment with the specified file name. It also sends a log message to the administrator’s mailbox.

Let us see the commands to search for emails with particular phrases or words coming in the email subject, copy them to the target folder, and delete them from the source mailbox.

Using this command, you can simply search and delete the messages having a specific phrase in the subject.

Search-Mailbox -Identity “user mailbox name” –SearchQuery Subject:”specific phrase or words” –DeleteContent

Run this command if you want to search specific messages that contain a specified phrase in the subject. It copies these messages to deleted messages folder and deletes those messages from the Source mailbox folder.

Search-Mailbox -Identity “user mailbox name” –SearchQuery Subject:”specific phrase or words” –TargetMailbox “BackupMailbox” –TargetFolder “DeletedMessages” –LogLevel Full -DeleteContent

After absorbing the technical approach for locating items within the Exchange user mailbox, you’ll find that mastering this skill is imperative for achieving precise results. Even the slightest oversight can potentially wreak havoc by compromising the integrity of your file data.

To streamline the search and conversion of items, whether they are stored in EDB files, live Exchange servers, or Office 365, users can rely on Kernel for Exchange Server. This highly efficient third-party EDB recovery software empowers users to effortlessly locate and convert mailbox items in a matter of minutes.

With its robust Search capabilities, this tool empowers users to efficiently locate specific emails using a range of criteria, including Subject, Body, From, To, Cc, Bcc, and more. Additionally, users can preview their search results before taking any action. Whether you need to selectively export, migrate, or save these items to meet your specific needs, this tool provides the flexibility to do so seamlessly. Furthermore, it offers the convenience of conducting subsequent searches within the search results themselves. This versatile tool supports searching within offline EDB files, live Exchange Server, and Office 365 environments. Notably, it also aids in the recovery of accidentally deleted Exchange mailbox items, making it an indispensable asset for email management and data retrieval.

Conclusion

The article demonstrates the precise utilization of the Exchange Management Shell for efficient email search and deletion on an on-premises Exchange Server. This versatile tool empowers administrators to seamlessly search for and delete mailbox items. In the event of accidental mailbox item deletions, a recommended solution is to employ reliable third-party Exchange Server data recovery software. By scanning the EDB file, this software effortlessly restores mailboxes from EDB file , ensuring a hassle-free recovery process.