Having trouble with Microsoft Teams? A corrupted user cache can sometimes lead to unexpected behavior in the application. This guide demonstrates how to automatically clear the Microsoft Teams user cache with PowerShell, potentially resolving various Teams issues.

Table of Contents

Benefits of Clearing the Teams Cache

  • Improved Performance: Clearing the cache can help streamline Teams by removing potentially outdated or corrupted data.
  • Enhanced Stability: Removing cached data can sometimes resolve crashes, freezes, or other stability issues within Teams.
  • Faster Troubleshooting: This method quickly eliminates the user cache as a potential culprit, allowing you to focus on other troubleshooting steps if necessary.

Clear Teams cache with PowerShell

This script automatically cleans the Microsoft Teams user cache while notifying the user if the application is currently running. This approach helps troubleshoot potential Teams issues by clearing potentially corrupted cached data.

Script Functionality:

  1. Checks for Running Teams: The script checks if Microsoft Teams is running.
  2. User Prompt (if Teams is running): A message box appears, informing the user about the need to close Teams and offering options to "Clear" or "Abort."
  3. Cleans User Cache and Restarts Teams (if confirmed): Upon confirmation, the script closes Teams, clears the cache (excluding "Backgrounds"), restarts Teams, and logs successful cache clearing.
  4. Clears Cache (if Teams is not running): If Teams is not running, the script directly clears the cache (excluding "Backgrounds") and logs successful cache clearing.

How to use the Script on demand

To use the script, you could just execute it, but that requires access to the device. A more flexible way is using the Remediation feature from Intune (Enterprise licenses required). With that you have the possibility to trigger a script on demand on a device basis:

Setup in Intune

Download the Script
Save the code as a .ps1 file (e.g., ClearTeamsCacheWithPrompt.ps1) or download it from GitHub (above).

Create a Remediation Package in Intune

  1. Navigate to: Intune > Devices > Windows > Scripts and remediations
  2. Hit + Create
  3. Give your package a name and a optional description.
  4. Upload the previous saved PowerShell script.
    (Since everything in in one script, we only need the detection)
    • In addition, set the script to run as the logged-on user in in 64bit context.
  5. All the other points you can skip, including the assignment. Cause we will use it only for on-demand actions.

Use the Remediation in a support scenario

Now that we have the remediation package configured we or any other user with the sufficient rights can use it to support users. To do so you have just to do 3 steps:

  1. Locate the Device
  2. Click on "Run remediation"
  3. Choos the package and your user's cache will be cleared.

And here is a short demo video of the whole process. The video is not sped up. So this is a real time example: