What It Does
For each user with a UID of 500 or higher and a home folder under /Users (or only TARGET_USER), the script finds the Teams cache folders that exist and empties them. For new Teams that means the Caches folder of its container and group container, the Library caches named com.microsoft.teams2, and the Cache, Code Cache and GPUCache folders of its web profile. For classic Teams it means the com.microsoft.teams caches, and under Application Support the Cache, Code Cache, GPUCache, blob_storage, tmp, Application Cache and Service Worker cache folders.
It empties the folders and keeps the folders themselves. It never touches settings, sign-in data, local storage or chats, and it only works on paths inside a user's Library that name Teams.
Teams must not be running for that user. When it is, that user is skipped with a warning, and the answer is SKIPPED if nobody could be cleared. Set QUIT_TEAMS to true and the script asks Teams to quit, waits, and then ends what is left of its processes before it clears the cache.
Teams rebuilds the cache itself, so its next start is slower than usual.
Before You Run It
- Run it with DRY_RUN=true first and read the list of folders it would empty.
- Grant the RMM agent Full Disk Access. Without it the script may be unable to inspect or empty an app container's cache.
- Tell the user before you set QUIT_TEAMS to true. Quitting Teams ends a call or meeting in progress.
- Expect the next Teams start to be slow while the cache refills.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: Low. Set DRY_RUN=true to list every change without making any.
- What it changes: Deletes the contents of the Microsoft Teams cache folders in each user's Library.
- Restart: It never restarts the machine.
- Typical run: Under 30 seconds.
- Example answer: "Cleared the Teams cache for 2 user(s): 5 folder(s), 612 MB freed"
- Tested before listing on macOS 27 (Apple silicon VM) with /bin/bash 3.2, run as root, against its own test cases.
Inputs
Pass an input as an argument (--input-name value), as an environment variable named as listed, which is how most RMMs pass script variables, or change its default in the DEFAULT_ lines near the top of the script. An argument wins over an environment variable, which wins over the default.
- TARGET_USER: Only this user. Default every user.
- QUIT_TEAMS: Quit Teams first if it is running. Default false.
Every script also takes DRY_RUN, OUTPUT_FORMAT (Text, Answer, Json or Csv), EXPORT_PATH and RESULT_FIELD, which writes the answer to an RMM custom field, unless the list above words one differently.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.