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