Using Powershell Microsoft Teams module in a GUI app will not shutdown the process when form closed

Copper Contributor

I have a GUI app written in Powershell that works correctly except when I connect to MicrosoftTeams (and even disconnect) then the GUI app process will not end. If I remove the connection to MSTeams the process ends correctly (not in task mgr process list anymore). So I'm confident I've narrowed the issue down to the MSTeams connect/disconnect.


Here is code snipet for connect/disconnect.

$script:msteamsSession = Connect-MicrosoftTeams -Credential $script:O365CredDefault

Disconnect-MicrosoftTeams -Confirm:$false


It does seem to be an issue in non-GUI scripts also.

When I run PS ISE and do MSTeams connect then close PS ISE, the process is still running. Yes I gave it time to shutdown.



3 Replies
Unfortunately remove-module -Name MicrosoftTeams didn't work
best response confirmed by DarusDP (Copper Contributor)


Not ideal or elegant but

Stop-Process -Id $PID 

seems to work


Hopefully Microsoft Teams module developers will discover the real problem and fix it.