Skip to content

Commit

Permalink
Refactor: Fixed the typing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MixeroTN committed Sep 17, 2023
1 parent 2efb6dd commit 6ab4155
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This is a PowerShell script that is designed to clean the cache of Microsoft Tea
⚠️ **Script requires administrator privileges to run.**

## Usage

- Launch `clearTeams.ps1`
- Grant administrator privileges
- The script will close any active Teams process and clear the Teams cache
Expand Down
71 changes: 37 additions & 34 deletions clearTeams.ps1
Original file line number Diff line number Diff line change
@@ -1,47 +1,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 powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
exit

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 | Stop-Process -Force
Write-Host "Closed the Teams process" -ForegroundColor Green
}catch{
Write-Host "No Teams process detected" -ForegroundColor Green
echo $_
Get-Process -ProcessName Teams -ErrorAction Ignore | Stop-Process -force
} catch {
Write-Host "No Teams process detected" -ForegroundColor Green
}
Write-Host "Clearing a Teams cache" -ForegroundColor Yellow

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 cleared" -ForegroundColor Green
}catch{
echo $_
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

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
}

0 comments on commit 6ab4155

Please sign in to comment.