How it works...

Since we are not supplying credentials when creating the ExchangeService object and we're not using impersonation, the search will be performed in the administrator mailbox, as this is the logged-on user. You probably noticed that the property set only contains a few key properties of each message. Although there are many more available properties that can be returned, as a best practice we should only retrieve the properties that interest us. That way, if we are executing the code over and over, perhaps even against multiple mailboxes, we are not burdening the Exchange servers by requesting unnecessary data.

The key to a successful search is constructing the appropriate AQS query. You can use an AQS query for specific properties ...

Get Microsoft Exchange Server 2016 PowerShell Cookbook - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.