This was a great help thank you for this answer AasimPathan-9021
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
3 answers
Sort by: Newest
-
-
Aasim Pathan 6 Reputation points
2021-06-18T06:56:10.59+00:00 Actually, all you need is a simple one-liner
Start-Process -File $env:LOCALAPPDATA\Microsoft\Teams\Update.exe -ArgumentList '--processStart "Teams.exe"'
-
Rich Matheisen 45,096 Reputation points
2021-03-03T03:28:13.897+00:00 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"'