Skip to main content

HelloID

Avoid timeout issue with on-premise Exchange

When Post-action scripts in Active Directory connect to on-premises Exchange, they may fail with the error messages: Error initializing exchange session for executing post action script and PowerShell script exceeded timeout of 30 seconds. This happens when the Exchange session takes longer than the default 30-second timeout, causing the scripts to stop early and fail or complete only partially.

To allow the scripts to run within the timeout period, reset the PowerShell environment by recycling the MSExchangePowerShellAppPool and MSExchangePowerShellFrontEndAppPool.

You can do this temporarily:

  • With PowerShell:

    Import-Module WebAdministration 
    Restart-WebAppPool -Name "MSExchangePowerShellAppPool" 
    Restart-WebAppPool -Name "MSExchangePowerShellFrontEndAppPool"
  • Manually:

    1. Open the Internet Information Services (IIS) Manager.

    2. In the Connections pane, expand the server node and click Application Pools.

    3. In the Application Pools pane, select MSExchangePowerShellAppPool and then click Recycle in the Actions pane.

    4. Repeat the process for MSExchangePowerShellFrontEndAppPool.

To permanently avoid the issue, create a schedule for recycling the MSExchangePowerShellAppPool and MSExchangePowerShellFrontEndAppPool using the built-in recycling options in IIS.

  1. Open IIS Manager.

  2. Navigate to Application Pools.

  3. Select MSExchangePowerShellAppPool.

  4. In the Actions pane, click Recycling…

  5. Check the box for Regular time intervals (in minutes) and set the interval to a suitable value (e.g., 720 minutes for 12 hours).

  6. Click Next, then Finish.

  7. Repeat the process for MSExchangePowerShellFrontEndAppPool.

For more information, see this Microsoft Learn article: Recycling Settings for an Application Pool <recycling>.