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 401 with Merge MailboxFolders.ps1 #60

Closed guillaumebottollier closed 2 months ago

guillaumebottollier commented 3 months ago

Dear @David-Barrett-MS

First Thanks for your work here, I'm sure it will help us a lot !

I have an issue with Merge MailboxFolders.ps1, i've completed all the steps but i get a connection refused. Scenario : I want to move all the Archive content to Mailbox of user a.

I've created the app, the secret... and run this command with options (fake here of course)

$SourceMailbox = "usera@corp.com" $clientId = "54f5ds4gf5-77c1-499f-809f-541ereggr2" $tenantId = "09reger-e2ab-4d49-b94b-dfgdf" $secretKey = "idsojfghdfkjghdfslkjhndskfnhn" # App only auth $redirectUrl = "http://localhost/code" # Delegate auth .\Merge-MailboxFolder.ps1 -SourceMailbox $SourceMailbox -SourceArchive -MergeFolderList @{"WellKnownFolderName.Inbox"= "Inbox"} -Office365 -OAuth -OAuthTenantId $tenantId -OAuthClientId $clientId -OAuthRedirectUri $redirectUrl

Then only difference with the procedure is that i grant the app permission for impersonation this way :

image

Then i get :

image

Can you help me here ? Thanks in advance !

David-Barrett-MS commented 2 months ago

For app permissions you need to pass in the secret key to the script. It is missing from your example:

.\Merge-MailboxFolder.ps1 -SourceMailbox $SourceMailbox -SourceArchive -MergeFolderList @{"WellKnownFolderName.Inbox"= "Inbox"} -Office365 -OAuth -OAuthTenantId $tenantId -OAuthClientId $clientId -OAuthRedirectUri $redirectUrl

The above will (attempt to) use delegated permissions which haven't been granted to your app registration (per the screenshot).