-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclearTeams.ps1
More file actions
50 lines (41 loc) · 1.86 KB
/
clearTeams.ps1
File metadata and controls
50 lines (41 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
param([switch]$Elevated)
function Check-Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Check-Admin) -eq $false) {
if ($elevated) {
exit
} else {
Start-Process (Get-Process -Id $PID).ProcessName -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}
exit
}
Write-Host "Closing the Teams process" -ForegroundColor Yellow
try{
Get-Process -ProcessName Teams -ErrorAction Ignore | Stop-Process -force
} catch {
Write-Host "No Teams process detected" -ForegroundColor Green
}
Write-Host "Cleaning the Teams cache" -ForegroundColor Yellow
try{
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\Cache" | Remove-Item -Confirm:$false -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\blob_storage" | Remove-Item -Confirm:$false -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\databases" | Remove-Item -Confirm:$false -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\gpucache" | Remove-Item -Confirm:$false -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\Indexeddb" | Remove-Item -Confirm:$false -recurse -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\Local Storage" | Remove-Item -Confirm:$false -recurse -force
Get-ChildItem -Path $env:APPDATA\"Microsoft\Teams\tmp" | Remove-Item -Confirm:$false -force
Write-Host "Roaming cache cleaned" -ForegroundColor Green
} catch {
echo $_
}
$challenge = Read-Host "Launch Teams? (Y/N)?"
$challenge = $challenge.ToUpper()
if ($challenge -eq "N") {
Stop-Process -Id $PID
} elseif ($challenge -eq "Y") {
Write-Host "Launching Teams" -ForegroundColor Yellow
Start-Process -FilePath $env:LOCALAPPDATA\Microsoft\Teams\current\Teams.exe
Stop-Process -Id $PID
}