'How to search and list an email from the Exchange Online mailbox by using Power Shell

I would like to search and list an emails with particular message subject from one mailbox within the Exchange Online. I do not want to copy that message or delete it. I just wanna to list all messages with particular subject. I tried "Search-Mailbox":

search-mailbox -EstimateResultOnly -identity [email protected] -searchquery 'subject:"Test message 1"'

But it shows only this:

RunspaceId       : <GUID>
Identity         : testmailbox
TargetMailbox    : 
Success          : True
TargetFolder     : 
ResultItemsCount : 1
ResultItemsSize  : 41.91 KB (42,919 bytes)

This in similar way - just copy the message to my mailbox - I cannot list it:

Get-Mailbox [email protected] -ResultSize Unlimited | Search-Mailbox -SearchQuery 'Body:"*Test message 1*"' -TargetMailbox [email protected] -TargetFolder Inbox

And by the way the Search-Mailbox is being retired since 2020.07.01.

Any ideas ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source