Search mailbox syntax

Rising Flight 3,751 Reputation points
2021-11-15T21:06:41.38+00:00

Hi All

i want to know mails from a particular user are residing in which folder for a users mailbox. i am using search mailbox syntax but i am getting error. how do i get this information from content search i am not sure of it.

Search-Mailbox -Identity john@mydomain.com -SearchQuery {From:"someuser@externaldomain.com" AND Received:"10/01/2021 00:00..11/16/2021 23:59"} -TargetMailbox "myaccount@mydomain.com" -TargetFolder "search" -LogOnly -LogLevel Full

Cannot save changes made to an item to store.

  • CategoryInfo : InvalidArgument: (:) [], ObjectNotFoundException
  • FullyQualifiedErrorId : [Server=IPPO111119,RequestId=asasfsdf6-sadfsf-adsf-adfds-sfdsdfdsfdfa,TimeStamp=11/15/2021 7:00:15 PM] [FailureCategory=Cmdlet-ObjectNotFoundException] sfasfdsfd
  • PSComputerName : outlook.office365.com
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,190 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,356 questions
{count} votes

Accepted answer
  1. Amit Singh 4,846 Reputation points
    2021-11-16T06:12:49.213+00:00

    Hi, based on my test result, if the subject has the character " ' ", the command will not work for mailbox search(DeleteContent):
    149644-1.png

    Besides, the parameter "received" couldn't be specified at a specific time, or you will not get any records about the message:
    149548-2.png

    Finally, you could try the following command which worked successfully in my lab environment(More details about the Received and other properties: Message properties and
    149549-3.png
    Search-Mailbox -Identity myuser@Company portal .com -SearchQuery {From:"John@jaswant .com" AND Subject:"Re: TEST: This isn't the correct mail ... for xyx or abc" AND (received>="<Received Start Date>" AND received<="Received End Date")} -DeleteContent -Force

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

    If an Answer is helpful, please click "Accept Answer" and upvote it.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Joyce Shen - MSFT 16,646 Reputation points
    2021-11-16T05:35:44.573+00:00

    Hi @Rising Flight

    I tried your syntax in my environment and it can work properly.
    149559-132559.png

    We may first try with another target mailbox to see whether the issue is related to the current specified target mailbox. Besides, you may also try changing the LogLevel to Suppress or Basic to see whether it works.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    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.

    0 comments No comments