Blog Post

Microsoft Teams Community Blog
3 MIN READ

Clearing the Microsoft Teams Cache - Centrally Managed with PowerShell and Microsoft Intune

Drago-Petrovic's avatar
Nov 30, 2022

Microsoft Teams is increasingly becoming the central hub in companies worldwide. Many have introduced Microsoft Teams as a collaboration platform or as a replacement for Skype for Business.

 

For some time now, telephony systems from other manufacturers have also been replaced by Microsoft Teams.

 

Microsoft offers different models of how telephony can be handled, for example: Direct Routing or Operator Connect.

 

When Microsoft Teams is used as a telephony solution, functions such as browsing through the address book become an unconscious but enormously important task that all users use.

 

From time to time there are problems in this (or other areas) that the search in the address book is not correct or entries cannot be found. Often the solution can be to delete the Teams cache.

 

Clearing the Teams cache on a local computer can be done relatively easily:

  • Fully close Microsoft Teams – Right click the Teams icon in the system tray (near the clock) and click Quit.
  • While holding down the Windows key, press R – this will open the Windows Run box.
  • Copy and paste this into the Run box: %appdata%\Microsoft\Teams
  • Delete everything in the folder
  • Relaunch Teams – it will ask you to sign in

 

This is one way in which this process can be done for individual users.

 

However, if this is to be done for multiple users, or is to be managed centrally, a different solution may be required:

 

The solution in this article is to execute a BAT file on the affected devices via a centrally managed tool (in this case Microsoft Intune).

 

This BAT file itself, looks like this:

 

In order to be able to distribute this BAT file with Intune, various points must be dealt with:

-Q: How is the BAT file distributed?

-A: Via PowerShell and Microsoft Intune

 

-Q: How is the BAT file made available?

-A: Directly via the PowerShell script, which is available on GitHub.

 

-Q: If this PowerShell script is distributed via Intune, how can I ensure that the script is not re-executed daily?

-A: The script was built to be executed only once.

 

Download PowerShell Script from GitHub

 

Structure of the PowerShell Script Explained

The PowerShell script has a modular structure.

 

In the first step, the script checks whether a specific registry entry exists on the target computer. This is the following key:

HKCU:Software\Microsoft\MSB365_Teams_clear_cache_Tool

 

If this key exists, the PowerShell script is terminated, and no further actions will be performed.

 

However, if this key does not exist, the script will continue to run.

 

In the second step, the script checks whether the directory "C: \MDM" already exists on the target computer. If this is not the case, this directory is created.

 

In the next step, the PowerShell script downloads the described BAT file from the GitHub repository. The corresponding BAT file with the name ClearTeamsCache.bat is then located in the directory "C: \MDM".

 

Now the BAT file that performs the Teams cache is executed in the PowerShell script.

 

A corresponding logging is stored in the subfolder "C:\MDM\Logging\ClearTeamsCache.txt".

 

The last step is to create the registry key that was requested at the beginning of the script.

This ensures that this script is not executed again with every update or after every restart.

 

 

Configuration Microsoft Intune

 

In the Endpoint Manager Portal we go to Devices > Scripts

 

Click on Add

 

Give the process a name

 


Select the script and use the configurations as shown in the picture.

 

 

Assign the script to the appropriate group

 

Complete the deployment.

 

You can find the link to the script further down in this article. Here you can see transparently how it works and how the BAT file is configured.

 

https://github.com/MSB365/ClearTeamsCache/tree/main

 

 

 

Published Nov 30, 2022
Version 1.0
  • I think clear cache it's more much complicated

    1, background files for Teams call/meeting is local file, they will not back if we delete them(%appdata%\Microsoft\teams\Backgrounds\Uploads)

    2, as we already begin this, I think it's better to make it in a bigger picture

    --I mean include local credential, local teams application file %localappdata%\Microsoft\teams, %localappdata%\Microsoft\TeamsMeetingAddin,%localappdata%\Microsoft\TeamsPresenceAddin

     

    my suggestion sounds like a reinstallation, but as Microsoft is useless for most cache issue, we have no choice

    in short, as a metaphor, instead of "delete user profile", I choose "reinstall windows system"

  • luvsql's avatar
    luvsql
    Steel Contributor

    I understand the need of the registry so it doesn't keep running but can non-admins create root folders and registry entries?  What if we need to clear the cache again at a later time?  Since the key exists, it won't run, so we need a way to run this "on demand" to all devices.

  • In my opinion, non-admins should not change entries in the registry.
    If the cache cleaning has to be done again, there are two options from my point of view.

     

    • 1. create a script in Intune that deletes the registry key again before you run the script on the user again. This command would then be:
      Get-Item HKCU:Software\Microsoft\MSB365_Teams_clear_cache_Tool | Remove-Item -Force -Verbose
    • 2. you take the sctipt, which is available for download on GitHub, and adapt line 103. There you change the name of the item property.


    I hope this helps you.

     

    PS:
    Regarding the question whether a reg key can be created in the context of the user: Yes, as it concerns the HKCU area. In general, this is possible.