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

Microsoft 365 Authentication Issue #8

Closed lachlanpatterson closed 1 year ago

lachlanpatterson commented 2 years ago

It looks like the URL in the script for Microsoft 365 authentication may be out of date. Getting a 404 error when using -Office365 and -OAuth

David-Barrett-MS commented 2 years ago

Which script are you referring to? I've updated the OAuth for several of the scripts but not all. If you can let me know which one I'll check and make the necessary changes.

lachlanpatterson commented 2 years ago

This is for the MergeMailboxFolder.ps1 script. Sorry for not specifying to begin with!

From: David @.> Sent: Friday, February 25, 2022 9:53 AM To: @.> Cc: Lachlan @.>; @.> Subject: Re: [David-Barrett-MS/PowerShell-EWS-Scripts] Microsoft 365 Authentication Issue (Issue #8)

Which script are you referring to? I've updated the OAuth for several of the scripts but not all. If you can let me know which one I'll check and make the necessary changes.

— Reply to this email directly, view it on GitHubhttps://github.com/David-Barrett-MS/PowerShell-EWS-Scripts/issues/8#issuecomment-1050921667, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAO72VKVEQAUMEHOVTIDMTTU46JWZANCNFSM5PKONMZA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

David-Barrett-MS commented 2 years ago

Interesting, as that is one of the scripts that is up-to-date. However, the log-in URL is determined by your tenant Id, so you need to ensure that is passed - you can't just use the -OAuth switch, you'll need to provide the other OAuth information too (minimum required would be tenant Id, but you may also need to set some of the other OAuth parameters).

lachlanpatterson commented 2 years ago

I think I see now. I'll take a closer look. Thanks!

From: David @.> Sent: Friday, February 25, 2022 10:50 AM To: @.> Cc: Lachlan @.>; @.> Subject: Re: [David-Barrett-MS/PowerShell-EWS-Scripts] Microsoft 365 Authentication Issue (Issue #8)

Interesting, as that is one of the scripts that is up-to-date. However, the log-in URL is determined by your tenant Id, so you need to ensure that is passed - you can't just use the -OAuth switch, you'll need to provide the other OAuth information too (minimum required would be tenant Id, but you may also need to set some of the other OAuth parameters).

— Reply to this email directly, view it on GitHubhttps://github.com/David-Barrett-MS/PowerShell-EWS-Scripts/issues/8#issuecomment-1050970732, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAO72VPNSSFVYFUIYSL6KBDU46QNBANCNFSM5PKONMZA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

knut1er commented 2 years ago

Hello David, Thnks for all of these scripts, that I try to understand. My goal is to use Create-MailboxFolder script, with MFA. I'm trying this one MergeMailboxFolder, and does not understand.

If I try this one: .\Merge-MailboxFolder.ps1 -SourceMailbox jlch@chandezon.fr -SourceArchive -MergeFolderList @{"TESTMERGE" = "TESTMERGE"} -Office365 -OAuth -OAuthTenantId c93fa772-c086-4e1f-9dc2-f71b37148556

... I can see redirect to localhost URI. Do I need to prevent this? Thanks

David-Barrett-MS commented 2 years ago

The OAuth settings must all come from your own tenant registration. You need to register the OAuth application in the Azure portal, per this guide: https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-authenticate-an-ews-application-by-using-oauth

You can then pass in the relevant details to the script using the OAuth parameters.

I will add some more guides when I get a chance to cover common scenarios and give more context to the existing examples.

Kevin-Netflow commented 2 years ago

Hi David,

First of all, thanks for all the work you have put into these amazing scripts. As for myself I manage to create powershell scripts to analyse mailboxes and ease the process of troubleshooting. On the other hand, EWS i'm struggling a bit.

For that mather, some years ago, I found a usefull script of yours for deleting empty folders in users mailboxes thru applicationimpersonation. Your script was called: Search-EmptyFolders.ps1 which is now get-emptyfolders.ps1. Extremely handy when Archiving was setup for a user and all those folders remained empty in the mailbox still causing preformance issues in Outlook.

Had problems with Basic Auth on tenants now. Found your get-emptyfolders.ps1 as a new version but does it support oauth?

David-Barrett-MS commented 1 year ago

Get-EmptyFolders.ps1 does not support OAuth. I'll add it when I get the chance. I've opened a new issue to track that.