David-Barrett-MS / PowerShell-EWS-Scripts

A collection of PowerShell scripts that use EWS to perform actions against Exchange mailboxes
MIT License
119 stars 13 forks source link

Merge-Mailboxfolder Impersonation error #2

Closed keselo closed 1 year ago

keselo commented 3 years ago

Hi David,

Thanks for creating this script to move mails from mailbox to mailbox. I have tried using this but encountered the errors below:

Merge-MailboxFolder.ps1 version 1.1.9 starting VERBOSE: Loading Microsoft.Exchange.WebServices.dll vSystem.Object[] found at: System.Object[] Using EWS Managed API found at: C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll

Processing mailbox mailbox@domain.com VERBOSE: Using default credentials VERBOSE: Currently caching 1 ExchangeService objects VERBOSE: [ThrottledFolderBind]Attempting to bind to folder MsgFolderRoot (xxx@a.com) Error (ThrottledFolderBind): Exception calling "Bind" with "3" argument(s): "The request failed. The remote server retur ned an error: (401) Unauthorized." VERBOSE: FAILED to bind to folder MsgFolderRoot (xxx@a.com) Failed to open source message store (xxx@a.com) Please check that you have impersonation permissions

I have confirmed that the user running has ApplicationImpersonation rights. Is there any other place that I should check?

David-Barrett-MS commented 3 years ago

Is this against Exchange Online? What parameters are you using when calling the script? Unauthorized means just that, so it's just a case of working out why. For Exchange Online, if MFA is enabled on a mailbox then you'd need to use OAuth to log-on (and would get an auth error otherwise).

keselo commented 3 years ago

Hi David,

Thanks for replying. This is against on prem Exchange 2013.

The parameters that I am using are .\Merge-MailBoxFolder.ps1 -sourcemailbox a@a.com -targetmailbox b@b.com -mergefolderlist inbox,"sent items" -searchfilter received:$archivedate -processsubfolders -EWSUrl "https://mail.test.com/EWS/Exchange.asmx" -createtargetfolder -LogFile $log -impersonate -verbose

This is run using an archive user who has impersonation rights.

I have checked by trying to login as the archive user to the target mailbox and it works. No MFA is turned on.