question

hyggejack avatar image
0 Votes"
hyggejack asked HelpDeskGuy75-9664 published

How to launch Microsoft Teams via PowerShell

Hi All! I'm creating a script that will clean the Microsoft Teams cache files. The script works by closing Teams, deleting all of the files except two folders, then (and this is where I'm having problems)...launch Microsoft Teams.

I also noticed that if Teams was already closed, it generates an error. I'm not sure if that can be fixed or now.

I've tried this Start-Process -File C:\Users\%username%\AppData\Local\Microsoft\Teams\Update.exe --process "Teams.exe" but this errors out.

Can someone help me with the code so that at the end it launches Microsoft Teams?

Here's the code I have:

    Stop-Process -Name Teams -Force
    $TeamsPath = $env:APPDATA+"\Microsoft\TeamsTest\"
    Get-ChildItem -Path $TeamsPath -Exclude "Backgrounds", "meeting-addin" | foreach ($_) {
        "CLEANING :" + $_.fullname
        Remove-Item $_.fullname -Force -Recurse
        "CLEANED... :" + $_.fullname
    }   
    Start-Process -File C:\Users\%username%\AppData\Local\Microsoft\Teams\Update.exe --process "Teams.exe"

And here are the errors the last line generates:

 Stop-Process : Cannot find a process with the name "Teams". Verify the process name and call the cmdlet again.
 At line:1 char:4
 +    Stop-Process -Name Teams -Force
 +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : ObjectNotFound: (Teams:String) [Stop-Process], ProcessCommandException
     + FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.StopProcessCommand
     
 Start-Process : A positional parameter cannot be found that accepts argument 'Teams.exe'.
 At line:8 char:4
 +    Start-Process -File C:\Users\%username%\AppData\Local\Microsoft\Te ...
 +    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : InvalidArgument: (:) [Start-Process], ParameterBindingException
     + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand

Thank you so much for looking at this with me!

~ Jack

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
4 Votes"
RichMatheisen-8856 answered SalihBaran-8690 commented

See if this works for you:

 # Stop Teams
 Get-Process "Teams" -ErrorAction SilentlyContinue | Stop-Process
 #
 # Do what you need to here
 #
 # change to the correct directory
 Set-Location ($ENV:USERPROFILE + '\AppData\Local\Microsoft\Teams')
 # start Teams
 Start-Process -File "$($env:USERProfile)\AppData\Local\Microsoft\Teams\Update.exe" -ArgumentList '--processStart "Teams.exe"'


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Amazing. I am using this exact solution to uninstall Zoom.
When Zoom is installed in Appdata, it isn't automatically updated.
Therefore, I have implemented auto-uninstall of Zoom with this Powershell command:

Set-Location ($ENV:USERPROFILE + '\AppData\Roaming\Zoom\uninstall')
Start-Process -File "$($env:USERProfile)\AppData\Roaming\Zoom\uninstall\Installer.exe" -ArgumentList '/uninstall'

After this is up and running, the users can install the MSI version of Zoom via Company Portal, Software Center or any 3rd party patch management app.

0 Votes 0 ·
AasimPathan-9021 avatar image
0 Votes"
AasimPathan-9021 answered

Actually, all you need is a simple one-liner


Start-Process -File $env:LOCALAPPDATA\Microsoft\Teams\Update.exe -ArgumentList '--processStart "Teams.exe"'

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HelpDeskGuy75-9664 avatar image
0 Votes"
HelpDeskGuy75-9664 answered HelpDeskGuy75-9664 published

This was a great help thank you for this answer AasimPathan-9021

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.