Clearing the Microsoft Teams Cache - Centrally Managed with PowerShell and Microsoft Intune
Published Nov 30 2022 08:00 AM 31.3K Views

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:

Picture1.png

 

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

DragoPetrovic_0-1669798404748.png

 

In the Endpoint Manager Portal we go to Devices > Scripts

DragoPetrovic_1-1669798404752.png

 

Click on Add

DragoPetrovic_2-1669798404753.png

 

Give the process a name

DragoPetrovic_3-1669798404756.png

 


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

 

DragoPetrovic_4-1669798404758.png

 

Assign the script to the appropriate group

DragoPetrovic_5-1669798404760.png

 

Complete the deployment.

DragoPetrovic_6-1669798404762.png

 

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

 

 

 

3 Comments
Co-Authors
Version history
Last update:
‎Nov 30 2022 08:00 AM
Updated by: