Purging the Rogue Teams Cache: Ending the Infinite Login Loop
Fix infinite login loops and stuck presence status by safely purging the Microsoft Teams cache. Includes a PowerShell script updated for the New Teams architecture.
Microsoft Teams MSIX Package Cache & Infinite Login Loop Repair Guide
6 min. read
The Ticket: The Pre-Meeting Panic
A high-level executive is trying to join a critical board meeting, but their Microsoft Teams client is trapped in a mesmerizing, infinite white login loop. Or perhaps their presence dot is permanently stuck on "Offline" while they are actively typing to you in a chat. They have tried clicking "Restart" on the error prompt twenty times to no avail. A standard PC reboot occasionally works, but not always. We need a targeted PowerShell strike to kill the rogue background processes, purge the corrupted token database, and get the client communicating cleanly with the Microsoft 365 cloud again.
Pre-Flight Check
- Permissions: Standard User account. (Do not run this as a Local Administrator or SYSTEM, as you need to target the currently logged-in user's specific AppData profile).
- Tools: PowerShell 5.1+.
- Impact: Low. All chat history, channels, and files are safely stored in the cloud. The user will simply have to log back in. Local preferences like Dark Mode or specific device settings might revert to default.
[!WARNING] The Risk Factor: Make sure the user is not actively trying to download a massive file within the Teams interface. Killing the process abruptly will sever active background file transfers.
The Solution: The Dual-Architecture Purge Script
The biggest mistake Tier 1 techs make today is using old scripts that only target Classic Teams. Microsoft completely overhauled the application architecture. You must target both the old Electron path and the New Teams MSIX package path.
PowerShell
# --- 404 & More: Microsoft Teams Cache Nuke ---
Write-Host "Hunting down rogue Teams processes..."
# Kill both New Teams (ms-teams) and Classic Teams (Teams)
Get-Process -Name "ms-teams", "Teams" -ErrorAction SilentlyContinue | Stop-Process -Force
# Give the file locks a moment to release
Start-Sleep -Seconds 3
# 1. Target New Teams (MSIX App Package)
$NewTeamsCache = "$env:LOCALAPPDATA\Packages\MSTeams_8wekyb3d8bbwe\LocalCache\Microsoft\MSTeams"
if (Test-Path $NewTeamsCache) {
Write-Host "Purging New Teams local cache..."
Get-ChildItem -Path $NewTeamsCache -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
# 2. Target Classic Teams (Electron)
$ClassicTeamsCache = "$env:APPDATA\Microsoft\Teams"
if (Test-Path $ClassicTeamsCache) {
Write-Host "Purging Classic Teams local cache..."
Get-ChildItem -Path $ClassicTeamsCache -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
}
Write-Host "SUCCESS: Cache cleared. Restarting Teams..." -ForegroundColor Green
# Kickstart the New Teams client
Start-Process "ms-teams:" -ErrorAction SilentlyContinue
The "Why" (Root Cause)
Why does Teams break so frequently? At its core, Microsoft Teams is essentially a highly modified web browser. Classic Teams was built on the Electron framework, and New Teams is built on Edge WebView2.
Just like Google Chrome, Teams stores a massive amount of local data to speed up load times: image thumbnails, presence status caches, and, most importantly, authentication tokens. When the client wakes up from a deep sleep state or switches between different Wi-Fi networks, the local authentication token can fall out of sync with the Azure Active Directory server. The local client tries to use a stale token, the server rejects it, and the client tries again immediately. The local SQLite database fails to overwrite the bad token, trapping the application in an infinite login loop.
Under the Hood (Technical Deep Dive)
The transition to "New Teams" changed how Windows handles the cache. Classic Teams dumped everything into the roaming %APPDATA% folder. This was notorious for bloating virtual desktop environments.
New Teams is an MSIX packaged application. Microsoft completely containerized it. The application now lives in a highly restricted sandbox inside the %LOCALAPPDATA%\Packages directory. When you run the purge script, you are explicitly targeting the LocalCache subfolder of the MSTeams_8wekyb3d8bbwe package.
By forcefully deleting the contents of this folder, you are shredding the IndexedDB files, the GPU shader cache, and the corrupted Azure AD token blobs. The next time you launch the executable, Teams is forced to reach out to the Web Account Manager (WAM) in Windows to request a fresh, clean authentication token directly from the Trusted Platform Module.
RMM & Automation Tips
- The "Run As User" Trap: If you push this script through your RMM background terminal, it will fail 99% of the time. RMM agents execute scripts as the
NT AUTHORITY\SYSTEMaccount. The script will dutifully wipe the cache located atC:\Windows\System32\config\systemprofile\AppData, completely missing the actual user's profile. You must configure your RMM script parameters to execute as the "Logged-In User". - Self-Service Portals: This is the perfect script to package into a clickable executable or place in a self-service IT portal (like CloudRadial). When a user complains about Teams acting up, you can tell them to click the "Fix Teams" button on their desktop, saving you a 15-minute remote session.
Troubleshooting & Edge Cases
- Edge Case 1: Hidden Background Locks. Sometimes the script fails with an "Access Denied" error on a specific database file. This usually means a hidden Office integration process (like Outlook attempting to sync calendar status) is holding a hard lock on the Teams file. Close Outlook, run the script again, and reopen both apps.
- Edge Case 2: The "We ran into an issue" Banner. If clearing the cache completely fails to fix a login issue, the problem has likely escalated to the Windows Web Account Manager. You will need to open Windows Settings, navigate to Accounts, select "Access work or school", disconnect the M365 account entirely, and reconnect it to rebuild the master token.
If you want to see more guides and scripts just like this, make sure to follow us on Twitter, check out the Facebook page, and sign up for the weekly 404 & More newsletter!