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.
Batch script
1 2 |
TASKKILL /IM Teams.exe /F rmdir C:\Users\"enter username"\AppData\Roaming\Microsoft\Teams /s /q |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
Write-Host "Closing Teams" try{ if (Get-Process -ProcessName Teams -ErrorAction SilentlyContinue) { Get-Process -ProcessName Teams | Stop-Process -Force Start-Sleep -Seconds 3 Write-Host "Teams sucessfully closed" }else{ Write-Host "Teams is already closed" } }catch{ echo $_ } Write-Host "Clearing Teams cache" try{ Get-ChildItem -Path C:\Users\"enter username"\AppData\Roaming\Microsoft\Teams | Remove-Item -Recurse -Confirm:$false Write-Host "Teams cache removed" }catch{ echo $_ } Write-Host "Cleanup complete.... Launch Teams" |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
Write-Host "Closing Teams" try{ if (Get-Process -ProcessName Teams -ErrorAction SilentlyContinue) { Get-Process -ProcessName Teams | Stop-Process -Force Start-Sleep -Seconds 3 Write-Host "Teams sucessfully closed" }else{ Write-Host "Teams is already closed" } }catch{ echo $_ } Write-Host "Clearing Teams cache" try{ Get-ChildItem -Path C:\Users\*\AppData\Roaming\Microsoft\Teams | Remove-Item -Recurse -Confirm:$false Write-Host "Teams cache removed" }catch{ echo $_ } Write-Host "Cleanup complete.... Launch Teams" |
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.