Viewing 2 reply threads
  • Author
    • #15602
      Michael Pietroforte
      Member Points: 42,263
      Author of the year 2018
      Rank: 4

      Sometimes, when you test PowerShell scripts with Exchange Online (Office 365), you will get this error message:

      New-PSSession: [] Connecting to remote server failed with the following error message:


      [Server=DB3PR05CA007,RequestId=53f9abce-bea1-4308-b73b-6b4e5add9871,TimeStamp=8/3/2013 2:04:12 PM] Fail to create a runspace because you have exceeded the maximum number of connections allowed: 3 for the policy party: MaxConcurrency. Please close existing runspace and try again.

      This happens whenever you open a remote session to Exchange Online in your script and didn’t close it afterward. Since the maximum number of connections allowed is 3, Office 365 won’t allow you to create a new session.

      You can display your open PowerShell sessions (“PSSessions”) with this cmdlet:


      If you see that you already have three sessions open, you can close them all with this command:

      Get-PSSession | Remove-PSSession

      To ensure that you don’t again exceed the maximum number of sessions, always close the session at the end of your PowerShell script with:

      Remove-PSSession <session>
    • #16404
      Timothy Warner
      Member Points: 1,400
      Rank: 3

      Hey Michael, I have verified this behavior, and the three administrative session limit seems to be “baked into” Exchange Online. See this TechNet link, where they say that you have to “wait for the sessions to expire” if you reach the concurrency limit of 3 sessions:

      So the salient question is, “How long does it take for a remote PowerShell session that was closed on the local box to expire?”

      The very bottom of this MS help page ( says:

      If you close the Windows PowerShell window without disconnecting from the server-side session, your connection will remain open for 15 minutes.

      I  guess I would build logic into my PowerShell script to ward against my inadvertently closing the session window. Here are some hacks from Stack Exchange users:

      Hope this helps,


    • #16413
      Michael Pietroforte
      Member Points: 42,263
      Author of the year 2018
      Rank: 4

      Tim, thanks for the tips. Inadvertently closing the window is probably the number reason why the PowerShell session hangs.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
© 4sysops 2006 - 2023


Please ask IT administration questions in the forums. Any other messages are welcome.


Log in with your credentials


Forgot your details?

Create Account