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

Error (ThrottledFolderBind): Exception calling "Bind" with "3" argument(s): "The request failed. The remote server returned an error: (401) Unauthorized." #14

Closed bertrandpons closed 1 year ago

bertrandpons commented 1 year ago

Hello @David-Barrett-MS,

Thank you for your great scripts!

What I would like to achieve in Exchange Online is to move folders from on shared mailbox to another shared mailbox in its archive.

Thus, when I run the script Merge-MailboxFolders.ps1:

.\Merge-MailboxFolders.ps1 -SourceMailbox <SOURCE_MAILBOX> -TargetMailbox <TARGET_MAILBOX> -TargetArchive -MergeFolderList @{"Inbox"= "WellKnownFolderName.Inbox"; "Sent Items"= "WellKnownFolderName.SentItems"} -ProcessSubfolders -CreateTargetFolder -Office365 -OAuthClientId <OAUTH_CLIENT_ID> -OAuthTenantId <OAUTH_TENANT_ID> -OAuthSecretKey <OAUTH_SECRET_KEY> -WhatIf

I get the following output:

Merge-MailboxFolders.ps1 version 1.2.3 starting
Using EWS Managed API found at: C:\Program Files (x86)\Microsoft Office\root\Office16\ADDINS\Microsoft Power Query for Excel Integrated\bin\Microsoft.Exchange.WebServices.dll

Processing mailbox <SOURCE_MAILBOX>
Error (ThrottledFolderBind): Exception calling "Bind" with "3" argument(s): "The request failed. The remote server returned an error: (401) Unauthorized."
Failed to open source message store (<SOURCE_MAILBOX>)

If I add '-Impersonate' parameter, I get the same error with this additional error: Please check that you have impersonation permissions

Do I have missed something related to permissions?

Thank you in advance.