Search for emails in mailbox

lalajee 1,366 Reputation points
2022-06-28T09:16:56.167+00:00

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 User2022@Domain.com -SearchQuery '(  
(BODY:"Word 1" OR "Word 2" OR "Word 3")   
OR  
(Subject:"Word 1" OR "Word 2" OR "Word 3")   
OR  
(attachment:"Word 1" OR "Word 2" OR "Word 3")  
)  
AND   
(  
(FROM:User 1 OR User 2 OR User 3)  
OR   
(TO:User 1 OR User 2 OR User 3)  
)   
AND   
(SENT:05/02/2022..07/03/2022)  
' -TargetMailbox "User@domain.com" -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.
3,429 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.
2,896 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.
6,091 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.
4,626 questions
1 vote

3 answers

Sort by: Most helpful
  1. Michel de Rooij 1,521 Reputation points Microsoft MVP
    2022-06-28T11:00:57.223+00:00

    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.


  2. KyleXu-MSFT 25,616 Reputation points
    2022-06-29T03:41:46.253+00:00

    @lalajee

    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 37,351 Reputation points
    2022-07-01T15:13:26.467+00:00

    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. https://learn.microsoft.com/en-us/visualstudio/vsto/how-to-programmatically-search-within-a- 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,

    https://learn.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps

    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,

    https://support.microsoft.com/en-us/office/manage-email-messages-by-using-rules-c24f5dea-9465-4df4-ad17-a50704d66c59

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

    https://www.vishalon.net/blog/move-outlook-emails-of-specific-date-range-to-a-folder

    ---------------------------------------------------------------------------------------------------------------------

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

    No comments