Exchange Online app-only cert auth: "Module could not be correctly formed" after successful token acquisition (RBAC for Applications)

Mark Stuart 0 Reputation points
2026-12-02T03:12:08.3133333+00:00

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)

  1. Original app, assigned the "Tenant AllowBlockList Manager" application role via New-ManagementRoleAssignment -App; later also temporarily granted the Exchange Administrator Entra directory role for isolation testing (since removed), then reverted to the narrow role only. Both configurations produced the identical failure.
  2. Brand-new app, created solely to rule out stale/corrupted state on app #1, assigned only "Tenant AllowBlockList Manager" via New-ManagementRoleAssignment -App, immediately after creation. Identical failure, tested within minutes of role assignment.

Both apps have:

  • Exchange.ManageAsAppV2 (Application permission, Office 365 Exchange Online API) added and admin-consented.
  • A confirmed, enabled role assignment, verified via Get-ManagementRoleAssignment -Role "Tenant AllowBlockList Manager" showing RoleAssigneeType: ServicePrincipal, Enabled: True, for the correct service principal Object ID in each case.

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)

  • Platform: Linux (Ubuntu/Mint, pwsh 7.7.0) AND Windows (PowerShell 5.1 / ExchangeOnlineManagement 3.11.1)
  • Module version: 3.6.0, 3.10.1, 3.11.1, all identical failure
  • Role assignment: Narrow custom application role ("Tenant AllowBlockList Manager" via New-ManagementRoleAssignment -App) AND separately full "Exchange Administrator" Entra directory role, both fail identically
  • App registration: Tested on an app with prior role-change history, AND a brand-new app registration with zero history, both fail identically
  • Certificate source: Self-signed cert generated via OpenSSL (Linux) AND via native New-SelfSignedCertificate (Windows), both fail identically
  • Certificate loading: -CertificateFilePath (PFX file) AND -CertificateThumbprint (Windows cert store), both fail identically
  • Network path: Tested on corporate VPN, and off VPN on a home network, identical failure both ways; no proxy configured, clean TLS handshake confirmed via curl to outlook.office365.com

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.

Exchange Online
Exchange Online

A cloud-based service included in Microsoft 365, delivering scalable messaging and collaboration features with simplified management and automatic updates.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Vasil Michev 128.8K Reputation points MVP Volunteer Moderator
    2026-12-02T07:48:49.8366667+00:00

    Exchange.ManageAsAppV2 is not the correct scope to use here, you need Exchange.ManageAsApp.

    Was this answer helpful?

    1 person found this answer helpful.

  2. AI answer

    2026-12-02T03:13:19.13+00:00

    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.
    • Exchange Application RBAC accepts special Application ... roles and documents Microsoft Graph and EWS as its supported protocols. Ordinary administrative roles such as Tenant AllowBlockList Manager are not listed as Application RBAC roles.^1^
    • Tenant Allow/Block List PowerShell management is documented for Organization Management, Security Administrator, or the Security Operator role group. The narrow 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^

    Configure the supported app-only path

    1. In Microsoft Entra admin center → App registrations → your app → API permissions, remove Exchange.ManageAsAppV2 if that is the literal permission currently assigned.
    2. Add:
      • Office 365 Exchange Online
      • Application permissions
      • Exchange.ManageAsApp
    3. Grant tenant-wide admin consent. Microsoft’s app-only procedure requires that exact permission name, with type Application and status Granted for the organization.^3^
    4. Assign the app’s Enterprise application/service principal the Security Administrator Microsoft Entra role. This role grants add/remove access for Tenant Allow/Block List operations; the Exchange Administrator role used in your isolation test is not among the documented Tenant Allow/Block List roles.^2^
    5. Wait for authorization caches to refresh before retesting. Application-permission changes can take between 30 minutes and two hours depending on recent app activity.^1^
    6. Connect using the tenant’s primary .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^

    Do not use this Application RBAC assignment for the target cmdlets

    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^

    If the corrected configuration still fails

    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:

    • UTC timestamp and correlation/request identifiers from module logs.
    • Sanitized Connect-ExchangeOnline -LogDirectoryPath output.
    • Module and PowerShell versions.
    • Tenant primary domain, app ID, and service-principal object ID.
    • Confirmation that the permission is exactly Exchange.ManageAsApp, admin-consented.
    • Confirmation that Security Administrator is assigned to the Enterprise application.
    • No token, PFX, certificate private key, or password.

    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

    1. Role Based Access Control for Applications in Exchange Online
    2. Allow or block email using the Tenant Allow/Block List
    3. App-only authentication in Exchange Online PowerShell and Security & Compliance PowerShell | Microsoft Learn
    4. New-TenantAllowBlockListItems-Description
    5. Test-ServicePrincipalAuthorization-Syntax
    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

    1 person found this answer helpful.
  3. Elena-VH 3,190 Reputation points Independent Advisor
    2026-12-02T03:42:39.4733333+00:00

    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.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.