Comprehensive Disk Cleanup
Category: System Maintenance
Performs a deep cleanup of temp files, recycle bin, Windows update cache, thumbnails, and system error dumps to free up disk space.
Write-Host "Cleaning TEMP directories..." -ForegroundColor Yellow
$tempPaths = @("$env:TEMP", "$env:windir\Temp")
foreach ($path in $tempPaths) {
try {
Remove-Item "$path\*" -Force -Recurse -ErrorAction Stop
Write-Host "Cleared: $path" -ForegroundColor Green
} catch {
Write-Host "Failed to clear $path: $_" -ForegroundColor Red
}
}
Write-Host "Cleaning Windows Update cache..." -ForegroundColor Yellow
Stop-Service wuauserv -Force
Remove-Item -Recurse -Force "C:\Windows\SoftwareDistribution\Download\*" -ErrorAction SilentlyContinue
Start-Service wuauserv
Write-Host "Clearing thumbnail cache..." -ForegroundColor Yellow
try {
del /s /q "%localappdata%\Microsoft\Windows\Explorer\thumbcache*.db"
Write-Host "Thumbnail cache cleared." -ForegroundColor Green
} catch {
Write-Host "Error clearing thumbnail cache." -ForegroundColor Red
}
Write-Host "Cleaning system error dump files..." -ForegroundColor Yellow
$systemCleanupPaths = @(
"C:\Windows\Minidump",
"C:\Windows\MEMORY.DMP",
"C:\Windows\Logs\CBS\CBS.log"
)
foreach ($path in $systemCleanupPaths) {
try {
Remove-Item $path -Force -Recurse -ErrorAction SilentlyContinue
} catch {}
}
Write-Host "Emptying Recycle Bin..." -ForegroundColor Yellow
try {
Clear-RecycleBin -Force -ErrorAction Stop
Write-Host "Recycle Bin emptied." -ForegroundColor Green
} catch {
Write-Host "Failed to empty Recycle Bin." -ForegroundColor Red
}
Write-Host "Comprehensive disk cleanup complete." -ForegroundColor Cyan
Comments
Log in to leave a comment.