Problem
You’re attempting to configure an on-premise server to use certificate authentication with Connect-ExchangeOnline to run unattended scripts (automation) scenarios using AzureAD applications and self-signed certificates as described in the following article:
App-only authentication for unattended scripts in the EXO V2 module
https://docs.microsoft.com/en-us/powershell/exchange/app-only-auth-powershell-v2?view=exchange-ps
However, you are presented with the following error when attempting to connect:
PS C:\> Connect-ExchangeOnline -CertificateThumbPrint "3968B23E6A91C8F7FF4A9587341E9B0FDB50DB0E" -AppID "ac28a30a-6e5f-4c2d-9384-17bbb0809d57" -Organization "bmabm.onmicrosoft.com"
----------------------------------------------------------------------------
The module allows access to all existing remote PowerShell (V1) cmdlets in addition to the 9 new, faster, and more reliable cmdlets.
|--------------------------------------------------------------------------|
| Old Cmdlets | New/Reliable/Faster Cmdlets |
|--------------------------------------------------------------------------|
| Get-CASMailbox | Get-EXOCASMailbox |
| Get-Mailbox | Get-EXOMailbox |
| Get-MailboxFolderPermission | Get-EXOMailboxFolderPermission |
| Get-MailboxFolderStatistics | Get-EXOMailboxFolderStatistics |
| Get-MailboxPermission | Get-EXOMailboxPermission |
| Get-MailboxStatistics | Get-EXOMailboxStatistics |
| Get-MobileDeviceStatistics | Get-EXOMobileDeviceStatistics |
| Get-Recipient | Get-EXORecipient |
| Get-RecipientPermission | Get-EXORecipientPermission |
|--------------------------------------------------------------------------|
To get additional information, run: Get-Help Connect-ExchangeOnline or check https://aka.ms/exops-docs
Send your product improvement suggestions and feedback to exocmdletpreview@service.microsoft.com. For issues related to the module, contact Microsoft support. Don't use the feedback alias for problems or support issues.
----------------------------------------------------------------------------
Error Acquiring Token:
Could not use the certificate for signing. See inner exception for details. Possible cause: this may be a known issue with apps build against .NET Desktop 4.6 or lower. Either target a higher version of .NET desktop - 4.6.1 and above, or use a different certificate type (non-CNG) or sign your own assertion as described at https://aka.ms/msal-net-signed-assertion.
New-ExoPSSession : One or more errors occurred.
At C:\Program
Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\2.0.5\netFramework\ExchangeOnlineManagement.psm1:475 char:30
+ ... PSSession = New-ExoPSSession -ExchangeEnvironmentName $ExchangeEnviro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-ExoPSSession], AggregateException
+ FullyQualifiedErrorId : System.AggregateException,Microsoft.Exchange.Management.ExoPowershellSnapin.NewExoPSSess
ion
PS C:\>
Image may be NSFW.Clik here to view.
You’ve verified that you have 2.0.3 or later of the EXO V2 module (2.0.5 in this case) by using the cmdlet:
Get-InstalledModule | FL
Image may be NSFW.Clik here to view.
Solution
One of the possible reasons why this error would be thrown is if you are not using PowerShell V7. Official document indicating that version 7.0.3 or later is required can be found here:
Supported operating systems for the EXO V2 module
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online-powershell-v2?view=exchange-ps
“Specifically, version 2.0.4 or later of the EXO V2 module is supported in PowerShell 7.0.3 or later.”
Use the of the following two cmdlets to determine which PowerShell you’re running:
Get-Host | Select-Object Version
$PSVersionTable
PS C:\> Get-Host | Select-Object Version
Version
-------
5.1.17763.1007
PS C:\> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17763.1007
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.1007
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
PS C:\>
Image may be NSFW.Clik here to view.
In this example, the installed PowerShell version is 5.1.17763.1007.
Proceed to download version 7.0.3 or later from GitHub: https://github.com/PowerShell/PowerShell/releases, install the EXO V2, and Connect-ExchangeOnline using a certificate for authentication should work.