Windows 11 Clear Temp Files -

foreach ($loc in $locations) if ($loc.Path -eq "RecycleBin") # Handle Recycle Bin separately $size = Get-RecycleBinSize if (-not $Silent) Write-Host "Checking $($loc.Name)..." -ForegroundColor Yellow if (-not $Silent) Write-Host " Size: $(Format-FileSize $size)" -ForegroundColor Gray if ($size -gt 0 -and (-not $Silent)) $confirm = Read-Host " Clear Recycle Bin? (Y/N)" if ($confirm -eq 'Y') Clear-RecycleBin -Force -ErrorAction SilentlyContinue $totalFreed += $size $results += [PSCustomObject]@Location = $loc.Name; Freed = $size if (-not $Silent) Write-Host " ✓ Cleared $(Format-FileSize $size)" -ForegroundColor Green elseif ($size -gt 0 -and $Silent) Clear-RecycleBin -Force -ErrorAction SilentlyContinue $totalFreed += $size elseif (Test-Path $loc.Path) $size = Get-FolderSize $loc.Path if (-not $Silent) Write-Host "Checking $($loc.Name)..." -ForegroundColor Yellow if (-not $Silent) Write-Host " Size: $(Format-FileSize $size)" -ForegroundColor Gray if ($size -gt 0 -and (-not $Silent)) $confirm = Read-Host " Clear this folder? (Y/N/A - All)" if ($confirm -eq 'Y' -or $confirm -eq 'A') $freed = Clean-Folder $loc.Path $totalFreed += $freed $results += [PSCustomObject]@Location = $loc.Name; Freed = $freed if (-not $Silent) Write-Host " ✓ Cleared $(Format-FileSize $freed)" -ForegroundColor Green if ($confirm -eq 'A') $Silent = $true elseif ($size -gt 0 -and $Silent) $freed = Clean-Folder $loc.Path $totalFreed += $freed else if (-not $Silent) Write-Host "Skipping $($loc.Name) (not found)" -ForegroundColor DarkGray if (-not $Silent) Write-Host ""

echo Cleaning prefetch... del /q /f /s "%SystemRoot%\Prefetch*" > nul 2>&1 windows 11 clear temp files

return $totalFreed

$totalFreed = 0 $locations = @()