Hello Kirt,
This behavior where Get-Mailbox succeeds but Set-Mailbox fails with a generic server-side error—strongly suggests a session state or token context issue within the PowerShell worker rather than a pure permissions problem, especially given that the exact same identity works seamlessly on an Azure VM.
In a Flex Consumption plan running Linux and the External PowerShell SDK, the out-of-process worker handles runspaces differently. Your key observation that a different Managed Identity context succeeds is a major clue: forcing a completely new authentication context establishes a clean session, successfully bypassing whatever stale or restricted token state is causing the failure in the primary runspace.
Here are the primary areas to investigate to resolve this:
1. Runspace and Session State Isolation:
The ExchangeOnlineManagement V3 module relies heavily on REST APIs and maintains session context. In Durable Functions, workers can reuse runspaces for Activity functions. If the session isn't explicitly closed, the token context for write operations might become invalid or clash with the external SDK's state management over time.
- Recommendation: Ensure you are explicitly clearing the connection at the very end of your Activity function using
Disconnect-ExchangeOnline -Confirm:$false. This forces the session state to clear before the runspace is reused by the worker.
2. Verify Identity-Based Storage Connections:
Durable Functions rely heavily on Azure Storage for managing execution state and orchestrations. When running in Flex Consumption, verify that your underlying function app storage connections are functioning optimally, as token retrieval delays at the host level can occasionally bubble up into activity execution timeouts or generic errors. Ensure your app settings use the required and valid identity parameters, specifically checking that AzureWebJobsStorage__accountName is configured properly for your storage connection. You can reference the official documentation here: Azure Functions identity-based connections
3. Module Version Compatibility:
The PowerShell worker on Linux Flex Consumption environments can be highly sensitive to specific module versions when dealing with headless, non-interactive REST API calls to Exchange Online.
To help narrow this down further and attempt a reproduction, I have a couple of follow-up questions:
- What exact version of the
ExchangeOnlineManagement module is defined in your requirements.psd1?
- Are you establishing the
Connect-ExchangeOnline connection locally inside the specific Activity function, or is it being handled at a broader scope?
Please let me know these details and your findings in Private messages.
Note: This response is drafted with the help of AI systems.