Have you looked at the Search-Mailbox cmdlet? https://learn.microsoft.com/en-us/powershell/module/exchange/search-mailbox?view=exchange-ps
Do note that you cannot target specific folders with it, if that's a requirement, you will have to use an EWS-based script.