2024-01-10 20:00:00 +01:00
|
|
|
# Clean Microsoft Teams Cache after stopping process
|
2023-12-22 20:00:00 +01:00
|
|
|
|
2024-01-10 20:00:00 +01:00
|
|
|
$SamAccountName = Read-Host -Prompt "SamAccountName"
|
2023-12-22 20:00:00 +01:00
|
|
|
$BasePath = "C:\Users"
|
2024-01-10 20:00:00 +01:00
|
|
|
$FoldersToDelete = @("$BasePath\$SamAccountName\AppData\Roaming\Teams","$BasePath\$SamAccountName\AppData\Roaming\Microsoft\Teams","$BasePath\$SamAccountName\AppData\Local\Packages\Microsoft.AAD.BrokerPlugin_cw5n1h2txyewy","$BasePath\$SamAccountName\AppData\Local\Microsoft\OneAuth","$BasePath\$SamAccountName\AppData\Local\Microsoft\IdentityCache")
|
|
|
|
|
|
|
|
Function Stop-MSTeams {
|
|
|
|
$MSTeamsProcessList = Get-Process -Name "Teams" -ErrorAction SilentlyContinue | Where-Object {($_.Description -eq "Microsoft Teams") -and ($_.Company -eq "Microsoft Corporation")}
|
|
|
|
if ($MSTeamsProcessList) {
|
|
|
|
# try gracefully first
|
|
|
|
$MSTeamsProcessList.CloseMainWindow()
|
|
|
|
# kill after five seconds
|
|
|
|
Sleep 5
|
|
|
|
if (-not $MSTeamsProcessList.HasExited) {
|
|
|
|
$MSTeamsProcessList |
|
|
|
|
Stop-Process -Force
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# Source : https://stackoverflow.com/a/28482050
|
2023-12-22 20:00:00 +01:00
|
|
|
|
2024-01-10 20:00:00 +01:00
|
|
|
}
|
2023-12-22 20:00:00 +01:00
|
|
|
|
2024-01-10 20:00:00 +01:00
|
|
|
Function Remove-MSTeamsCacheDirectory {
|
|
|
|
foreach ($IndividualFolder in $FoldersToDelete) {
|
|
|
|
Write-Host Remove-Item -Recurse -Force -Path $IndividualFolder
|
|
|
|
}
|
2023-12-22 20:00:00 +01:00
|
|
|
}
|
2024-01-10 20:00:00 +01:00
|
|
|
|
|
|
|
Stop-MSTeams
|
|
|
|
Remove-MSTeamsCacheDirectory
|
|
|
|
|