Created
September 22, 2023 14:21
-
-
Save codywilliamson/34a4c0a0394f605d667a2459c1f50f19 to your computer and use it in GitHub Desktop.
Clear Teams' cache & optionally persist settings
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
function Clear-TeamsCache { | |
[CmdletBinding(SupportsShouldProcess = $true)] | |
param ( | |
# Determine if settings should persist after clearing cache | |
[Parameter()] | |
[switch] | |
$PersistSettings | |
) | |
begin { | |
$cacheFolderPath = "$($env:APPDATA)\Microsoft\Teams" | |
Write-Verbose "Cache folder identified as: $cacheFolderPath" | |
$settingsFile = "$cacheFolderPath\desktop-config.json" | |
Write-Verbose "Settings file identified as: $settingsFile" | |
} | |
process { | |
Write-Verbose "Getting Teams process" | |
$proc = Get-Process 'Teams' -ErrorAction SilentlyContinue | |
Write-Verbose "Stopping Teams process" | |
$proc | Stop-Process | |
if ($PersistSettings -eq $true) { | |
$config = Get-Content -Path $settingsFile | ConvertFrom-Json -ErrorAction SilentlyContinue | |
Write-Verbose "Captured existing settings in memory" | |
} | |
Write-Verbose "Removing cache" | |
$cacheItems = Get-ChildItem $cacheFolderPath | |
$cacheItems | Remove-Item -Recurse -Force | |
if ($PersistSettings -eq $true) { | |
Write-Verbose "Attempting to apply existing settings" | |
$config | ConvertTo-Json -Compress | Set-Content -Path $settingsFile -Force | |
} | |
$startProcessArgs = @{ | |
FilePath = "$($env:LOCALAPPDATA)\Microsoft\Teams\Update.exe" | |
ArgumentList = '--processStart "Teams.exe"' | |
} | |
Write-Verbose "Starting Teams back up" | |
Start-Process @startProcessArgs | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment