Category filter

Script to clear cache for Microsoft Teams app on Windows devices

Is the Microsoft Teams app failing to open on your Windows device? Is it working slowly? Does the static tab load an empty page? A convenient solution to all this would be to clear the cache of the Teams app. Unfortunately, Microsoft has yet to implement a user-friendly way to clear the cache with the push of a button. Instead, we could use PowerShell and batch scripts to clear the cache from the Teams app. Hexnode UEM allows IT admins to remotely deploy these scripts to the endpoints using the Execute Custom Script action.

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Batch script

TASKKILL terminates any open Teams app processes. It uses parameters /IM for specifying the image name of the Teams app and /F for forcing the termination.

Clearing the Teams app cache involves deleting all files and folders in the C:\Users\"enter username"\AppData\Roaming\Microsoft\Teams directory using the rmdir command. While the /s parameter deletes the specified directory and all its subdirectories, the /q parameter ensures the deletion of the directory without any prompt for confirmation. Replace "enter username" in the command with the name of the user account for which the app cache is to be cleared.

PowerShell script

Clear Teams app cache for a single user account

The Get-Process cmdlet gets the Teams app, which the Stop-Process cmdlet uses to kill the app if it is running on the device.

The Get-ChildItem -Path C:\Users\"enter username"\AppData\Roaming\Microsoft\Teams | Remove-Item -Recurse -Confirm:$false command removes the folder containing the app cache files. Replace "enter username" in the command with the name of the user account for which the app cache is to be cleared.

Clear Teams app cache for all user accounts

What happens at the device end?

After the successful execution of each of the provided scripts, the cache of the Microsoft Teams app on the device will be cleared, resulting in the termination of the app.

Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository