There's more...

One piece of interesting information not returned by the code in the previous example is the body of the message. This is because there are a number of properties that the FindItems method will not return, one of which is the message body. In order to retrieve the message body, we can bind it to the message after the search has been performed using the ID of the message.

Let's extend the previous code so that we can retrieve the body of the message and add the ability to impersonate the target mailbox. Add the following code to a file called MailboxSearch.ps1:

 Param($query,$mailbox) Add-Type -Path C:\EWS\Microsoft.Exchange.WebServices.dll $svc = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService $id = New-Object ...

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.