Search for emails in mailbox

lalajee 1,811 Reputation points

Hi, I need to search for emails in an user mailbox and then export these emails into pst file

It needs to have following

search of emails to be as follows,

All emails between User 1 and User 2

That include either in the subject, attachment name or body of the email the following names/terms
Word 1
Word 2

Between 02 Feb 2022 and 05 Mar 2022

What is the best way to do this, Do I need to use powershell to search mailbox or attached it to my outlook. (This mailbox is over 1.5TB)

I did try to use the search function but i'm not sure if this is the correct way or not

Search-mailbox -Identity -SearchQuery '(  
(BODY:"Word 1" OR "Word 2" OR "Word 3")   
(Subject:"Word 1" OR "Word 2" OR "Word 3")   
(attachment:"Word 1" OR "Word 2" OR "Word 3")  
(FROM:User 1 OR User 2 OR User 3)  
(TO:User 1 OR User 2 OR User 3)  
' -TargetMailbox "" -TargetFolder "ProjectHamilton" -LogLevel Full -whatif  
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,727 questions
Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,048 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,217 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,275 questions
{count} vote

3 answers

Sort by: Most helpful
  1. Michel de Rooij 1,531 Reputation points MVP

    If this is on-prem, you can directly export to ST using New-MailboxExportRequest.
    If this is online, you can use Search-Mailbox as indicated. However, Search-Mailbox will be deprecated in favor of New-ComplianceSearch. Using ExchangeLocation, and when search is finished, you can export results to a PST. Easiest is through the Purview (compliance) portal, or use New-ComplianceSearchAction -SearchName ... -Export -Format FxStream -ArchiveFormat SinglePst. Need to retrieve the exported PST through portal though.

    1 person found this answer helpful.

  2. KyleXu-MSFT 26,196 Reputation points


    Based on my testing, there exist some issue when use "Subject" and "Body" in the same search. So, I would suggest you create two search for them:

    New-MailboxExportRequest -Mailbox UserA -ContentFilter "(Received -Gt '05/01/2018') -and (Received -lt '06/30/2022') -and ((Subject -like '*sub*') -or (Subject -like '*Test*'))" -FilePath "\\EXCH\Shared\1.pst"  
    New-MailboxExportRequest -Mailbox UserA -ContentFilter "(Received -Gt '05/01/2018') -and (Received -lt '06/30/2022') -and ((Body -like '*body*') -or (Body -like '*test*'))" -FilePath "\\EXCH\Shared\2.pst"  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

  3. Limitless Technology 39,186 Reputation points

    Hi Lalajee,

    Greetings for the day! We are happy to help you regarding handling emails in user mailboxes.

    Kindly try following options.

    Option 1: The standard way to handle this is to allow a service to watch for the specific emails in the Mailbox.

    Please try following steps.

    1. Create a console application which can read user mailboxes and watch for emails with specific condition. specific-folder?view=vs-2022
    2. Host this stand alone exe in a windows scheduler job and have it to monitor the user mailboxes
    3. Once specific emails are received in user outlook, service can handle it and move it specific folder in an common mailbox that can be configured.

    Option 2: If its an on premises exchange, please try using PowerShell scripts to handle this.

    Try using "Search-Mailbox" command to move emails with specific condition.

    Kindly verify details from below link,

    Option 3: If you are trying to handle theses within your own mail box, try using "rules" part of outlook.

    Outlook rule will have all the options you have requested and it can scan the emails which have already received in your mailbox.

    Kindly look into following link,

    Incase you need detailed steps with images, kindly verify this link -


    --If the reply is helpful, please Upvote and Accept as answer. --

    0 comments No comments