Forum Discussion
PowerShell Remote session getting disconnected with below error in every 150sec to 180 sec.
Since we have zero idea what you're doing, it might also pay to check the limits applied to different subscriptions while simultaneously verifying the licences you have had assigned to your are the same (where applicable) as those assigned to your colleagues.
It sounds like you're running into some kind of deliberate throttling.
Edited to include the following information
Based on the following thread (at the bottom):
Then if this relates to the Exchange Online PowerShell module (I'm going to refer to the V2 module), you might want to use the -PSSessionOption in the call Connect-ExchangeOnline .
- Connect-ExchangeOnline (ExchangePowerShell) | Microsoft Docs
- New-PSSessionOption (Microsoft.PowerShell.Core) - PowerShell | Microsoft Docs
Note
The OperationTimeout does not dictate for how long your command may execute. It dictates how long your local client waits for any kind of a response.
So, if you're running an inefficient query that causes the Exchange Online services to take Donkey's ages to run, then it's possible your client will hit the 180 second default operation wait limit, and having received nothing back from Exchange, will proceed to terminate the operation. This might (again, I'm making a lot of assumptions here) be the issue you're facing.
How to check your current operation timeout limit
Get-PSSession -Name "ExchangeOnlineInternalSession_*" | ForEach-Object { [PSCustomObject]@{ Id = $_.Id; Name = $_.Name; State = $_.State; OperationTimeout = $_.Runspace.ConnectionInfo.OperationTimeout; } }
How to specify a different operation timeout during the connection
A value of 0 means there is no timeout limit. This should cause the client to wait indefinitely (doesn't stop the service from cancelling the operation, but that's outside your control and may relate to the per subscription limits linked in the initial part of my post.)
Connect-ExchangeOnline -Organization robertsonpayne.onmicrosoft.com -ShowBanner:$false -PSSessionOption (New-PSSessionOption -OperationTimeout 0);
If you re-run the checking process, you should find you get output like this:
Cheers,
Lain
- sumabiswAug 24, 2022Copper Contributor
Hi Robertson.
I run your command and found the below details :
I am not sure but look like this time need to update as unlimited , Please suggest..
- LainRobertsonAug 24, 2022Silver Contributor
No, that shows a value of 180,000, which is 180,000 milliseconds, 180 seconds, or, in other words, three minutes.
Since three minutes is the default setting, this makes sense.
You might want to try the command I listed earlier to set the OperationTimeout to a value of 0, as 0 allows your client to wait indefinitely.
Cheers,
Lain
- sumabiswAug 24, 2022Copper Contributor