Forum Discussion
Connect-ExchangeOnline - Unauthorized
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.Id
Thanks for your help.