Forum Discussion
Connect-ExchangeOnline - Unauthorized
Oh yeah, that's right. Now one step further. I'm getting this error upon connecting:
Connect-ExchangeOnline -CertificateThumbprint $thumbprint -AppId
$appId -ShowBanner:$false -Organization $tenant -Verbose
VERBOSE: Returning precomputed version info: 3.4.0
VERBOSE: ModuleVersion: 3.4.0
VERBOSE: [ThreadID: #] Trying to get a new token from AAD
VERBOSE: [ThreadID: #] Trying to acquire token based on UI flow
VERBOSE: [ThreadID: #] Successfully acquired new token for Cert based flow.
VERBOSE: [ThreadID: #] Successfully got a token from AAD
VERBOSE: ConnectionContext Removed
OperationStopped: The role assigned to application 6eb9890f-dbeb-4e6d-b2fb-2e4c698fa7c0 isn't supported in this scenario. Please check online documentation for assigning correct Directory Roles to Azure AD Application for EXO App-Only Authentication.
If the cert was wrong i.e. not match between Windows and Azure cert stores the error would read:
Do you have an idea? Thank you.
- VasilMichevAug 20, 2024MVPYou need to assign a role such as Exchange Admin or Exchange Recipient admin.., the next step in the documentation...
- colonel_claypooAug 22, 2024Iron Contributor
VasilMichev Couldn't find the role in Entra. Only way to assign the role was through this PowerShell and not what is in the documentation. Here're for future use in case anyone stumbles over it here:
# Connect to Azure AD if not already connected
Connect-AzureAD# Get the service principal for Exchange Online
$exchangeServicePrincipal = Get-AzureADServicePrincipal -Filter "AppId eq '00000002-0000-0ff1-ce00-000000000000'"# Find the Exchange.ManageAsApp role
$appRole = $exchangeServicePrincipal.AppRoles | Where-Object {$_.Value -eq "Exchange.ManageAsApp"}# Get your application's service principal
$servicePrincipal = Get-AzureADServicePrincipal -Filter "AppId eq ''"# Assign the role to your application
New-AzureADServiceAppRoleAssignment -ObjectId $servicePrincipal.ObjectId -PrincipalId $servicePrincipal.ObjectId -ResourceId $exchangeServicePrincipal.ObjectId -Id $appRole.IdThanks for your help.