Adding the X-AnchorMailbox header will make the script more efficient in OnPrem scenarios by causing us to proxy directly to the server where the specified mailbox lives, instead of to the server corresponding to the authenticated user, which is the impersonation account in this case.
foreach ($mailAddress in $mailAddresses) {
$ewsService.HttpHeaders.Clear()
$ewsService.HttpHeaders.Add("X-AnchorMailbox", $mailAddress)
Adding the X-AnchorMailbox header will make the script more efficient in OnPrem scenarios by causing us to proxy directly to the server where the specified mailbox lives, instead of to the server corresponding to the authenticated user, which is the impersonation account in this case.