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

[GetTokenWithCertificate] Failed to load MSAL. Cannot continue with certificate authentication. #37

Closed GeorgeUgly closed 1 year ago

GeorgeUgly commented 1 year ago

I try to use certificate auth with latest script 1.3.2

2023/10/24 10:43:34 [Merge-MailboxFolder.ps1] Merge-MailboxFolder.ps1 version 1.3.2 starting VERBOSE: Loading Microsoft.Exchange.WebServices.dll v15.00.0913.015 found at: C:\Users\hongzhou\Downloads\MergeFolderTest\Microsoft.Exchange.WebServices.dll 2023/10/24 10:43:34 [LoadEWSManagedAPI] Using EWS Managed API found at: C:\Users\hongzhou\Downloads\MergeFolderTest\Microsoft.Exchange.WebServices.dll

Processing mailbox user17@xx.xx.com VERBOSE: Loading Microsoft.Identity.Client.dll v4.57.0.0 found at: C:\Users\hongzhou\Downloads\MergeFolderTest\Microsoft.Identity.Client.dll VERBOSE: Requesting token using certificate auth New-Object : A constructor was not found. Cannot find an appropriate constructor for type Microsoft.Exchange.WebServices.Data.OAuthCredentials. At C:\Users\hongzhou\Downloads\MergeFolderTest\Merge-MailboxFolder.ps1:634 char:28

Failed to connect to source mailbox 2023/10/24 10:43:35 [Merge-MailboxFolder.ps1] Script finished in 00:00:01.1597260

I put all dlls within same folder. Mode LastWriteTime Length Name


-a---- 2014/12/20 2:02 1130264 Microsoft.Exchange.WebServices.dll
-a---- 2023/10/17 7:26 1654384 Microsoft.Identity.Client.dll
-a---- 2022/7/27 11:07 18832 Microsoft.IdentityModel.Abstractions.dll

all dlls are from nuget install nuget.exe install Microsoft.Identity.Client nuget.exe install Microsoft.Exchange.WebServices

Please help check, thanks.

David-Barrett-MS commented 1 year ago

Try using the EWS dll from this repository see if that helps. This isn't an issue with the script, it seems to be a dependency issue of some kind. You can also add -Verbose and -OAuthDebug to get more information.

GeorgeUgly commented 1 year ago

Try using the EWS dll from this repository see if that helps. This isn't an issue with the script, it seems to be a dependency issue of some kind. You can also add -Verbose and -OAuthDebug to get more information.

Thanks, I use a wrong Thumbprint....my bad. It works fine now.