SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-2627702%22%20slang%3D%22en-US%22%3EUsing%20Powershell%20Microsoft%20Teams%20module%20in%20a%20GUI%20app%20will%20not%20shutdown%20the%20process%20when%20form%20closed%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2627702%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20a%20GUI%20app%20written%20in%20Powershell%20that%20works%20correctly%20except%20when%20I%20connect%20to%20MicrosoftTeams%20(and%20even%20disconnect)%20then%20the%20GUI%20app%20process%20will%20not%20end.%20If%20I%20remove%20the%20connection%20to%20MSTeams%20the%20process%20ends%20correctly%20(not%20in%20task%20mgr%20process%20list%20anymore).%20So%20I'm%20confident%20I've%20narrowed%20the%20issue%20down%20to%20the%20MSTeams%20connect%2Fdisconnect.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20code%20snipet%20for%20connect%2Fdisconnect.%3C%2FP%3E%3CP%3E%24script%3AmsteamsSession%20%3D%20Connect-MicrosoftTeams%20-Credential%20%24script%3AO365CredDefault%3C%2FP%3E%3CP%3EDisconnect-MicrosoftTeams%20-Confirm%3A%24false%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20does%20seem%20to%20be%20an%20issue%20in%20non-GUI%20scripts%20also.%3C%2FP%3E%3CP%3EWhen%20I%20run%20PS%20ISE%20and%20do%20MSTeams%20connect%20then%20close%20PS%20ISE%2C%20the%20process%20is%20still%20running.%20Yes%20I%20gave%20it%20time%20to%20shutdown.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2627702%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2628235%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Powershell%20Microsoft%20Teams%20module%20in%20a%20GUI%20app%20will%20not%20shutdown%20the%20process%20when%20form%20clo%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2628235%22%20slang%3D%22en-US%22%3ETry%20unloading%20the%20module%20as%20well%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2628954%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20Powershell%20Microsoft%20Teams%20module%20in%20a%20GUI%20app%20will%20not%20shutdown%20the%20process%20when%20form%20clo%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2628954%22%20slang%3D%22en-US%22%3EUnfortunately%20remove-module%20-Name%20MicrosoftTeams%20didn't%20work%3C%2FLINGO-BODY%3E
Occasional 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 (Occasional Contributor)
Solution

@DarusDP 

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.