- Thu, Sep 12 2013 at 1:51 pm #15602Michael PietroforteKeymasterMember Points: 42,263Rank: 4
Sometimes, when you test PowerShell scripts with Exchange Online (Office 365), you will get this error message:
New-PSSession: [pod51049psh.outlook.com] Connecting to remote server pod51049psh.outlook.com 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:
- Sun, Nov 10 2013 at 7:08 pm #16404Timothy WarnerModeratorMember Points: 1,400Rank: 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: http://technet.microsoft.com/en-us/library/jj984289(v=exchg.150).aspx
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 (http://help.outlook.com/en-us/140/cc952755.aspx) 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,
- Tue, Nov 12 2013 at 1:39 am #16413Michael PietroforteKeymasterMember Points: 42,263Rank: 4
Tim, thanks for the tips. Inadvertently closing the window is probably the number reason why the PowerShell session hangs.
- You must be logged in to reply to this topic.