Bug - PowerShell Teams Module 2.3.1 - Private SfBPowerShellSessionViaTeamsModule is never closed

New Contributor

I think I've found a bug in the PowerShell TeamsModule 2.3.1


The repro steps are quite straightforward:


- open 3 PowerShell instances
- call Connect-Teams in each of them
- Call Get-CSOnlineUser in the 1st, 2nd, and 3rd instance
- Call Disconnect-Teams in each of them


- open a 4th PowerShell instance
- Call connect-teams
- Call Get-CSOnlineUser
- Error: Get-CsOnlineSession : Connecting to remote server failed with the following error message : The
WS-Management service cannot process the request. The maximum number of concurrent shells for this user has been exceeded. Close existing
shells or raise the quota for this user. For more information, see the about_Remote_Troubleshooting Help topic.


Looking at the source code of the PS modules and also decompiling the private assemblies I noticed that the variuos SfbO cmdlet rely on TrpsSessionPsCmds to retrieve a Session object.
Therefore I've found a workaround that proves the bug:


after calling DisconnectTeams in the 1st shell, call:


$session = Get-PSSession


Check that there is a PSSession that is still alive:
$session | Format-List


ComputerType : RemoteMachine
ComputerName :
ContainerId :
VMName :
VMId :
ConfigurationName : Microsoft.PowerShell
InstanceId : 163877d5-81e6-464c-b88e-343609f88e70
Id : 3
Name : SfBPowerShellSessionViaTeamsModule_baba9e35-22d3-425b-b575-657090b56145
Availability : Available
ApplicationPrivateData : {SessionInfo, PSVersionTable}
Runspace : System.Management.Automation.RemoteRunspace
State : Opened
IdleTimeout : 900000
OutputBufferingMode : None
DisconnectedOn :
ExpiresOn :


You can repeat the same step in shell 2 and 3 and see that you will get similar results.


More proof that those sessions should have been deleted:
In one of the first 3 shells call:
Remove-PSSession -session $session


Now go to the 4th shell and run Get-CSOnlineUser again and you will see it working.


The Remove-PSSession should be automatically invoked by Disconnect-MicrosoftTeams otherwise the PSSession will be pending for a while preventing other sessions to be opened.

3 Replies
best response confirmed by ThereseSolimeno (Microsoft)

Hi @Riccardo_Trocca  thanks for taking the time.  The Uservoice feedback forum is the place to report bugs and make feature requests, and then other users can vote on them and track their progress.  

Hi @Riccardo_Trocca 
We faced exactly the same issue with PowerShell Teams Module 2.3.1 and Azure Function that you described. Did you found out a workaround for this issue? As function execution for different tenants gives error.

Tried manually to remove session by calling Remove-PSSession but this didn't help. Maybe we are doing something wrong

Hi @Pavlo770, what I did was to call Remove-PSSession in the way I describe here:
Dangling SfBO sessions with Microsoft Teams Module 2.x | by Riccardo Trocca | May, 2021 | Medium

I noticed that under certain conditions Get-PSSession returns null and, of course, in that case we are stuck. We had to redesign our solution to work around this issue, sadly. I tried to report this to Microsoft but they told me that this is "by design". I hope they will fix this stuff soon.