Files
management-scripts/Fix-MicrosoftTeams.ps1
T

28 lines
1.3 KiB
PowerShell
Raw Normal View History

2022-03-24 17:37:27 -04:00
# Make sure Microsoft Teams is installed
2022-03-24 17:26:29 -04:00
If ( Test-Path "${Env:LocalAppData}\Microsoft\Teams\Update.exe" ) {
# Get all running Teams processes
$ProcessList = (Get-Process -Name 'teams' -ErrorAction SilentlyContinue)
If ( $ProcessList ) {
2023-10-05 13:11:38 -04:00
Write-Output "Stopping Microsoft Teams"
2022-03-24 17:26:29 -04:00
Try { $ProcessStopped = $true ; $ProcessList | Stop-Process -Force }
Catch { LogErr $_.Exception.Message }
} Else { $ProcessStopped = $false }
# Remove all cached content
$CacheDir = "${Env:AppData}\Microsoft\Teams"
If ( Test-Path $CacheDir ) {
2023-10-05 13:11:38 -04:00
Write-Output "Removing all cached data for Microsoft Teams"
2022-03-24 17:26:29 -04:00
Try { Remove-Item $CacheDir -Recurse -Force }
Catch { LogErr $_.Exception.Message }
2023-10-05 13:11:38 -04:00
} Else { Write-Output "Could not clear cached data for Microsoft Teams because the directory could not be found: ${CacheDir}" }
2022-03-24 17:26:29 -04:00
# Restart Teams if we needed to close it before clearing the cache
If ( $ProcessStopped ) {
2023-10-05 13:11:38 -04:00
Write-Output "Starting Microsoft Teams"
2022-03-24 17:26:29 -04:00
Try { Start-Process "${Env:LocalAppData}\Microsoft\Teams\Update.exe" -ArgumentList "--processStart ""Teams.exe""" }
Catch { LogErr $_.Exception.Message }
}
2023-10-05 13:11:38 -04:00
} Else { Write-Output "Cannot clear cache for Microsoft Teams because it isn't installed" }