Share via

Durable Function errors with MI on Set-Mailbox

Kirt Sawaya 0 Reputation points Microsoft Employee
2026-05-22T22:13:25.38+00:00

I’m seeing an issue running Exchange Online Set- cmdlets* (e.g., Set-Mailbox) from an Azure Durable Function.

Environment

  • Plan: Flex Consumption
  • OS: Linux
  • PowerShell Durable Functions with ExternalDurablePowerShellSDK = True
  • Auth: Managed Identity (Connect-ExchangeOnline -ManagedIdentity)

Behavior

  • Managed Identity permissions are correctly configured
  • Same identity works on an Azure VM without issue
  • In the Durable Function (Activity function):
    • Get-Mailbox → works
      • Set-Mailbox → fails

Example:

PowerShell

Connect-ExchangeOnline -ManagedIdentity

 

Get-Mailbox -Identity [EMAIL REDACTED] # Works

Set-Mailbox -Identity [EMAIL REDACTED] -LitigationHoldEnabled $true # Fails

Error

EXCEPTION: A server side error has occurred because of which the operation could not be completed. Please try again after some time. If the problem still persists, please reach out to MS support.

 

Key Observation

If I execute Set-Mailbox inside a script block using a different Managed Identity context, the command succeeds—even within the same function.

Expected Behavior

Set-Mailbox should succeed in the Durable Function, consistent with behavior on an Azure VM using the same identity.


Questions

  • Is this a known limitation with Set- cmdlets* in Durable Functions (Linux / Flex Consumption / External SDK)?
  • Could this be related to how the PowerShell worker or Exchange Online session is handled in this environment?
  • Are there recommended configurations or workarounds for running EXO write operations here?
Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.


2 answers

Sort by: Most helpful
  1. Sina Salam 29,101 Reputation points Volunteer Moderator
    2026-05-24T14:10:06.9233333+00:00

    Hello Kirt Sawaya ,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having Durable Function errors with MI on Set-Mailbox.

    The issue is not proven to be a Durable Functions write-cmdlet limitation.

    With the scenario and strongest evidence you provided that Set-Mailbox succeeds inside the same Function when executed under another Managed Identity context.

    Therefore, the direct fix is:

    1. Explicitly specify the intended user-assigned Managed Identity with -ManagedIdentityAccountId. - https://learn.microsoft.com/en-us/powershell/exchange/connect-exo-powershell-managed-identity?view=exchange-ps
    2. Verify that exact identity has Exchange.ManageAsApp. - https://learn.microsoft.com/en-us/powershell/exchange/connect-to-exchange-online-powershell?view=exchange-ps
    3. Verify that exact identity has Exchange RBAC rights for Set-Mailbox -LitigationHoldEnabled. - https://learn.microsoft.com/en-us/powershell/exchange/find-exchange-cmdlet-permissions?view=exchange-ps
    4. Validate mailbox Litigation Hold licensing. - https://learn.microsoft.com/en-us/microsoft-365/admin/misc/create-litigation-hold-mac?view=o365-worldwide
    5. Run connect/execute/disconnect inside the Durable activity function, not as a shared/stale session. - https://learn.microsoft.com/en-us/azure/durable-task/common/durable-task-code-constraints?tabs=csharp&pivots=durable-functions

    If the issue still reproduces after those checks, then collect the failing activity invocation ID, Exchange request/correlation information, module version, Managed Identity object ID/client ID, and exact UTC timestamp, and open a Microsoft support case as a potential Exchange Online service-side failure. But based on the evidence, the root cause to eliminate is wrong or underprivileged Managed Identity being used by the Function, not Durable Functions itself. - https://learn.microsoft.com/en-us/powershell/module/exchangepowershell/get-managementroleassignment?view=exchange-ps

    Use the associated links for more reading and detail steps.

    I hope this is helpful! Do not hesitate to let me know if you have any other questions, steps or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    Was this answer helpful?

    0 comments No comments

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

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.