Forum Discussion

eliekarkafy's avatar
Mar 09, 2023

How to Delete Microsoft Teams Cache for All Users via PowerShell

The Microsoft Teams cache can be deleted manually by deleting all the files and folders in the %appdata%\Microsoft\Teams directory for each user profile. This however can be tedious and can be automated using PowerShell via one line of script.

 

Get-ChildItem -Path "$env:USERPROFILE\AppData\Local\Microsoft\Teams" -Recurse | Remove-Item -Force -Recurse

 

Note: It's important to close the Microsoft Teams app on all devices and clear the cache for all users to ensure that the cache is completely cleared.

  • RolandEhle's avatar
    RolandEhle
    Copper Contributor

    eliekarkafy Because more and more users have the "New Teams App" running, I decided to write a little function which will cover Cache deletion for both versions. Teams Client must be in running state before starting the Script.

    function clear-TeamsCache {
        # see https://learn.microsoft.com/en-us/microsoftteams/troubleshoot/teams-administration/clear-teams-cache
        $teamsrunning = 0
        $newteams = 0
    
        if (get-process | Where-Object {$_.ProcessName -ilike "*teams"}) {
            $teamsrunning = 1
            Try {
                get-Process -ProcessName ms-teams -ErrorAction Stop
                $newteams = 1
                $procs = get-process -ProcessName ms-teams
                $executable = $procs.Path
            }
            Catch {
                Write-Host "Modern Teams not running" -ForegroundColor Yellow
                $procs = get-process -ProcessName Teams
                $executable = $procs[0].Path
            }
    
            Write-Host "Stopping Teams Process(es). Please Wait...." -ForegroundColor Cyan
            $procs | Stop-Process -Force
            Start-Sleep -Seconds 5
            Write-Host "Processes have been stopped...." -ForegroundColor Cyan
    
            if ($newteams -eq 0) {
                $teamspath = $env:AppData + "\Microsoft\Teams\*"
                Write-Host "Clearing Teams Cache...." -ForegroundColor Green
                Get-ChildItem $teamspath -directory | Where-Object name -in ('application cache','blobstorage','databases','GPUcache','IndexedDB','Local Storage','tmp') | ForEach-Object {Remove-Item $_.FullName -Recurse -Force}
            } else {
                $teamspath = $env:LOCALAPPDATA + "\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams"
                Write-Host "Clearing Teams Cache...." -ForegroundColor Green
                Get-ChildItem $teamspath | Foreach-Object {Remove-Item $_.FullName -Recurse -Force}
            }
    
            Write-Host "Starting Teams again....." -ForegroundColor Green
            Start-Process -FilePath $executable
        } else {
            Write-Host "No Teams Client running. Please start Teams client and then come back and run this Script again" -ForegroundColor Red
        }
    }

Resources