Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds clear cache for new Teams #916

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions blog/2022-06-06-how-to-clear-teams-cache-with-powershell.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ tags:
- powershell
- snippet
---
How to clear Teams cache using PowerShell. Be careful about removing your custom backgrounds!

Clearing Teams cache is one of the first steps in troubleshooting client-side issues with Microsoft Teams. Very often it's the only step.
Clearing Teams cache is one of the first steps in troubleshooting client-side issues with Microsoft Teams. Very often it's the one and only step.

In this article I'm presenting a code snippet to automate this process. The code might then be used as a self-service activity. What do you think - how many tickets would be immediately solved if your users had such a tool?

<Tip>

Update December 2023 - the article now covers both new Teams and classic Teams application

</Tip>

## The manual way and its issue

Microsoft provides a dedicated article on how to [Clear Teams cache](https://docs.microsoft.com/en-us/microsoftteams/troubleshoot/teams-administration/clear-teams-cache).
Expand All @@ -32,7 +36,33 @@ The solution for above is to have a script doing it instead.

There's one more thing to be aware of. Some of our client-side settings will still be lost. Example of these setting is the preview mode - we need to opt-in for it manually. So far I haven't found a way to cover these settings in the script.

## The script
## The script for new Teams

The lines below will remove all the temporary files for new Teams client. It will, however, leave the _Backgrounds_ folder intact.

The script also stops the Teams process on the machine. Once the cleanup is done, it starts it once again.

```powershell
$proc = Get-Process 'ms-teams' -ErrorAction SilentlyContinue
$cacheFolderPath = "$($env:LOCALAPPDATA)\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams"
$proc | Stop-Process
$cacheItems = Get-ChildItem $cacheFolderPath -Exclude 'Backgrounds'
$cacheItems | Remove-Item -Recurse -Force
$teamsAppId = 'MSTeams_8wekyb3d8bbwe!MSTeams'
$startProcessArgs = @{
FilePath = 'explorer.exe'
ArgumentList = "shell:AppsFolder\$teamsAppId"
}
Start-Process @startProcessArgs
```

The differences between the script for new and classic Teams are:

- Different process name (was _teams_, is _ms-teams_)
- Different folder for storing cache
- Different way to start the app - previously we started the executable, now we need to start [the Universal Windows App (UWP)](https://stackoverflow.com/q/46893260/9902555).

## The script for classic Teams

The lines below will remove all the temporary files from the _%appdata%\Microsoft\Teams_. It will, however, leave the _Backgrounds_ folder intact.

Expand Down
Loading