A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Exchange.ManageAsAppV2 is not the correct scope to use here, you need Exchange.ManageAsApp.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Summary
Unable to establish an app-only (certificate-based) Exchange Online PowerShell session using the ExchangeOnlineManagement module. Authentication to Azure AD always succeeds (a valid token is issued), but the subsequent step where the module resolves the session's available cmdlets consistently fails with: Module could not be correctly formed. Please run Connect-ExchangeOnline again.
This occurs 100% of the time, across every variable we have been able to control for (see elimination matrix below). We believe this points to either a module/service bug in how Exchange Online resolves RBAC/cmdlet availability for app-only cert-based sessions, or a tenant-side configuration issue not visible to us from the client side.
Goal
Automate Tenant Allow/Block List (sender block) management via New-/Get-/Remove-TenantAllowBlockListItems, from an unattended backend service (no interactive user).
App registrations tested (both exhibit identical failure)
Both apps have:
Exact repro steps
$securePwd = Read-Host -AsSecureString -Prompt "PFX password"
Connect-ExchangeOnline -AppId <AppId> -CertificateFilePath "<path>\cert.pfx" -CertificatePassword $securePwd -Organization <tenant>.onmicrosoft.com -ShowBanner:$false -Verbose
Also reproduced using -CertificateThumbprint against a cert in the Windows local machine certificate store.
Verbose output (identical every time) 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 ParentContainsErrorRecordException: Module could not be correctly formed. Please run Connect-ExchangeOnline again.
Elimination matrix (all combinations tested; all fail identically)
What we're hoping someone can help with
Why would Exchange Online fail to return a valid cmdlet/RBAC manifest for these app-only certificate-based sessions despite successful authentication and a confirmed, enabled role assignment? We suspect either:
(a) a bug in how "RBAC for Applications" / Exchange Administrator role resolution interacts with the REST-backed module-forming step in ExchangeOnlineManagement v3.x for app-only sessions, or
(b) a tenant-level configuration issue that isn't visible or actionable from the client side.
Happy to provide additional diagnostic logs (Connect-ExchangeOnline -LogDirectoryPath output) on request.
A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.
Exchange.ManageAsAppV2 is not the correct scope to use here, you need Exchange.ManageAsApp.
AI answer
Use the documented Exchange.ManageAsApp application permission and assign the service principal a supported Microsoft Entra role that grants Tenant Allow/Block List management—Security Administrator—instead of assigning the ordinary Tenant AllowBlockList Manager Exchange role with New-ManagementRoleAssignment -App.
The configuration described combines two different RBAC models:
Exchange.ManageAsApp authorizes app-only Exchange Online PowerShell connectivity.Tenant AllowBlockList Manager are not listed as Application RBAC roles.^1^Tenant AllowBlockList Manager permission works only when assigned directly through Exchange admin center → Roles → Admin Roles, which is a user/role-group assignment path—not an Application RBAC assignment.^2^Exchange.ManageAsAppV2 if that is the literal permission currently assigned.Exchange.ManageAsApp.onmicrosoft.com domain:Connect-ExchangeOnline `
-AppId $AppId `
-CertificateFilePath $PfxPath `
-CertificatePassword $PfxPassword `
-Organization "tenant.onmicrosoft.com" `
-ShowBanner:$false
The app-only documentation supports Connect-ExchangeOnline from module version 2.0.4 onward, so your tested 3.x versions satisfy that requirement.^3^
Then check command exposure before modifying data:
Get-Command Get-TenantAllowBlockListItems `
-ErrorAction Stop
Get-TenantAllowBlockListItems `
-ListType Sender
For the intended operation:
New-TenantAllowBlockListItems `
-ListType Sender `
-Block `
-Entries "[Email]" `
-NoExpiration
New-TenantAllowBlockListItems supports Sender entries and requires permissions before it is exposed or executable.^4^
Remove or disregard this assignment for the connection test:
New-ManagementRoleAssignment `
-App <service-principal> `
-Role "Tenant AllowBlockList Manager"
For Application RBAC, Exchange requires an Exchange service-principal pointer and an Application role. Microsoft documents roles such as Application Mail.Read, Application Mail.Send, and Application EWS.AccessAsApp; it does not document Tenant AllowBlockList Manager as an application role.^1^
Test-ServicePrincipalAuthorization is useful only for actual Application RBAC grants; it deliberately tests access granted through that model and does not validate permissions granted separately through Microsoft Entra roles.^5^
At that point, the repeated cross-platform results make further certificate, network, or module-version rotation low value. Open a Microsoft 365 support case as a probable tenant-side EXO session-bootstrap issue and provide:
Connect-ExchangeOnline -LogDirectoryPath output.Exchange.ManageAsApp, admin-consented.The successful token acquisition establishes certificate authentication, but it does not establish that Exchange accepted the permission/role combination needed to construct the session’s command set.
References
Dear Mark Stuart,
Based on the information you've provided, the authentication portion appears to be working correctly because the certificate-based flow is successfully obtaining an access token from Microsoft Entra ID. The failure occurs afterward, when the ExchangeOnlineManagement module attempts to build the Exchange session and determine which cmdlets are available to the application.
Since you have already ruled out multiple variables including different ExchangeOnlineManagement versions, Windows and Linux hosts, different certificates, different app registrations, different role assignments, and different network paths, this does not look like a typical certificate or permission-consent issue.
In this case, you can refer to the AI Answer's suggestions above as they cover the most relevant troubleshooting steps for validating the service principal, RBAC assignments, and Exchange Online application permissions.
However, I cannot rule out a backend Exchange Online issue involving RBAC for Applications or service-principal cmdlet discovery within your tenant. Unfortunately, that layer is not visible from a public forum, and community members cannot access tenant-side Exchange Online service diagnostics.
Therefore, I recommend opening a support request with Microsoft 365 Support in the M365 Admin Center and providing the ExchangeOnlineManagement logs along with the exact correlation IDs and timestamps. The Exchange Online engineering team can inspect the backend RBAC resolution and cmdlet manifest generation process, which is not exposed to customers or community members. For reference: Get support for Microsoft 365 for business
Thank you for your patience and understanding. If you have any questions or if I have misunderstood anything, please feel free to reach out. Looking forward to your update.