Last active
October 25, 2024 07:31
-
-
Save Thadah/33946794819d773dc2b9b93259abe6ea to your computer and use it in GitHub Desktop.
Clears New Teams cache and restarts the application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If the script throws a policy error, execute it with the command below | |
# Set-ExecutionPolicy Unrestricted -Scope Process -Force -ErrorAction SilentlyContinue; ls -Recurse *.ps*1 | Unblock-File; .\"clearNewTeamsCache.ps1" | |
# Stop Teams Process | |
function Stop-Teams { | |
$teamsProcessName = "ms-teams" | |
$teams = Get-Process -Name $teamsProcessName -ErrorAction SilentlyContinue | |
if ($null -ne $teams){ | |
Write-Host "Teams Process Found, stopping..." -ForegroundColor Yellow | |
Stop-Process -Name $teamsProcessName -Force | |
Start-Sleep 5 | |
} | |
$teams = Get-Process -Name $teamsProcessName -ErrorAction SilentlyContinue | |
if ($null -ne $teams){ | |
Write-Host "Teams Process Successfully Stopped" -ForegroundColor Green | |
} | |
else { | |
Write-Host "Teams Process still hasn't stopped, waiting 2 seconds..." -ForegroundColor Green | |
Start-Sleep 2 | |
} | |
} | |
# Clear Teams Cache for New Teams Installation | |
function Clear-New-Teams-Cache { | |
$teamsPackageBasePath = "C:\Users\$env:USERNAME\AppData\Local\Packages" | |
$teamsPackagePath = (Get-ChildItem $teamsPackageBasePath -Directory | Where-Object { $_.Name -match 'MSTeams_' }).FullName | |
if ($teamsPackagePath -eq $null) { | |
Write-Host "Teams package path not found." -ForegroundColor Red | |
return | |
} | |
Write-Host "Clearing New Teams Disk Cache" -ForegroundColor Yellow | |
try { | |
$EBWebViewPath = Join-Path $teamsPackagePath "LocalCache\Microsoft\MSTeams\EBWebView" | |
$profilePath = (Get-ChildItem $EBWebViewPath -Directory | Where-Object { $_.Name -match 'WV2Profile_' }).FullName | |
if ($profilePath -eq $null) { | |
Write-Host "Teams profile path not found." -ForegroundColor Red | |
return | |
} | |
$subFolders = @("Cache*", "WebStorage", "database", "blob_storage", "IndexedDB", "Local Storage", "Code Cache", "CacheStorage") | |
foreach ($folder in $subFolders) { | |
$path = Join-Path $profilePath $folder | |
if (Test-Path $path) { | |
Get-ChildItem -Path $path -Recurse | Remove-Item -Recurse -Confirm:$false -ErrorAction SilentlyContinue | |
} | |
} | |
Write-Host "New Teams Disk Cache Cleaned" -ForegroundColor Green | |
} | |
catch { | |
Write-Output $_ | |
} | |
} | |
function Restart-Teams { | |
try { | |
# This will launch the default Teams application, be sure to have the protocol handler set to the new teams app | |
Start-Process "msteams:" | |
Write-Host "Teams restarted successfully." -ForegroundColor Green | |
} | |
catch { | |
Write-Host "Error: $_" -ForegroundColor Red | |
} | |
} | |
# Main | |
$challenge = Read-Host "Are you sure you want to delete Teams Cache? This will stop the Teams process (Y/n)" | |
$challenge = $challenge.ToUpper() | |
if ($challenge -eq "N") { | |
Stop-Process -Id $PID | |
} | |
try { | |
Stop-Teams | |
Clear-New-Teams-Cache | |
Restart-Teams | |
} | |
catch { | |
Write-Output $_ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment