Forum Discussion
jangliss
Aug 18, 2021Steel Contributor
Teams Powershell and Active Connections
With the shift in recent PowerShell modules after v2, and merging all the SfB commands into it, it has changed the way you connect. However, because PowerShell Remoting is a fickle beast, especially when it comes to using a cloud hosted services such as Teams, remote sessions sometimes just disappear, time out, or break. I previously handled this in scripts using Get-PSSession and looking at the state, if it was broken, I'd force a reconnect. So my scripts looked something like this:
function Connect-MSTeams {
if ($ForceReconnect -or (@(Get-PSSession -Name 'SfBPower*').Count -eq 0) -or (@(Get-PSSession -Name 'SfBPower*').State -contains 'Broken')) {
Get-Module tmp* | Where-Object{ $_.Description -like '*OcsPowershellOAuth*' } | Remove-Module
Get-PSSession -Name 'SfBPowerShell*'| Remove-PSSession
$cs = New-CsOnlineSession
Import-PSSession -Session $cs -AllowClobber
}
}
Connect-MSTeams
This worked great until v2, and now I don't see any sessions when execute Get-PSSession
As Teams PowerShell sessions still barf and die randomly, how does everybody else handle this? There is no handy function like Get-MicrosoftTeamsSession or easy way to check the health of a session, meaning you have to wrap every command in try/catch with specific catches for session issues.
Hello how are you? you are right this changed recently.
I noticed that, Get-PSSession will return something only when you call -Cs* cmdlets, so if you run Get-Team you will not have anything but if you call, for example, Get-CsCallingLineIdentity you will:
- Said that, reconnection should automatically work with latest versions (if you connected interactively), did you experience reconnection issues?