Windows 11 Clear Temp Files |best| Guide
echo Cleaning system temp... del /q /f /s "%SystemRoot%\Temp*" > nul 2>&1 rmdir /q /s "%SystemRoot%\Temp" > nul 2>&1 mkdir "%SystemRoot%\Temp" > nul 2>&1
# 6. Windows Update Cache $windowsUpdate = "$env:SystemRoot\SoftwareDistribution\Download" $locations += @Path = $windowsUpdate; Name = "Windows Update Cache"
Write-Host "========================================" -ForegroundColor Cyan Write-Host " Windows 11 Temporary Files Cleaner " -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" 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 ""
# Display summary Write-Host "========================================" -ForegroundColor Cyan Write-Host "Summary:" -ForegroundColor Cyan foreach ($result in $results) Write-Host " $($result.Location): $(Format-FileSize $result.Freed)" -ForegroundColor Green echo Cleaning system temp
$WScriptShell = New-Object -ComObject WScript.Shell $shortcut = $WScriptShell.CreateShortcut($shortcutPath) $shortcut.TargetPath = "powershell.exe" $shortcut.Arguments = "-NoProfile -ExecutionPolicy Bypass -File `"$scriptPath`"" $shortcut.WorkingDirectory = Split-Path $scriptPath $shortcut.IconLocation = "shell32.dll,24" $shortcut.Description = "Clear Windows 11 Temporary Files" $shortcut.Save()
echo Cleaning prefetch... del /q /f /s "%SystemRoot%\Prefetch*" > nul 2>&1 Name = "Recent Files"
# 4. Recent Files $recent = "$env:APPDATA\Microsoft\Windows\Recent" $locations += @Path = $recent; Name = "Recent Files"

