@echo off setlocal set HONESTY_SPEED_REPORT=1 powershell -NoProfile -Command "$p='%~f0'; $t=Get-Content -LiteralPath $p -Raw; $i=$t.LastIndexOf('###HONESTY-SPEED###'); if ($i -lt 0) { exit 1 }; $s=$t.Substring($i + 19).TrimStart([char]13,[char]10); Set-Content -LiteralPath ($env:TEMP + '\Honesty-Speed.ps1') -Value $s -Encoding UTF8" if errorlevel 1 ( echo Could not read the cleanup script. pause exit /b 1 ) powershell -NoProfile -ExecutionPolicy Bypass -File "%TEMP%\Honesty-Speed.ps1" echo. echo Finished. The report opened in your browser. pause exit /b ###HONESTY-SPEED### # Honesty Speed. Removes temporary files, browser caches, and the recycle bin, then flushes DNS. # Programs, documents, photos, and saved passwords stay. Startup programs are listed and left on. $ErrorActionPreference = 'Continue' $ProgressPreference = 'SilentlyContinue' $script:reportOnly = $env:HONESTY_SPEED_REPORT -eq '1' $script:total = [int64]0 $script:rows = New-Object System.Collections.Generic.List[string] function Esc([string]$s) { if ([string]::IsNullOrEmpty($s)) { return '' } return (($s -replace '&', '&') -replace '<', '<') -replace '>', '>' } function Add-Row([string]$name, [string]$detail) { $script:rows.Add('' + (Esc $name) + '' + (Esc $detail) + '') } function Format-Size([int64]$bytes) { if ($bytes -ge 10MB) { return ('{0:N0} MB' -f ($bytes / 1MB)) } if ($bytes -ge 1MB) { return ('{0:N1} MB' -f ($bytes / 1MB)) } if ($bytes -ge 1KB) { return ('{0:N0} KB' -f ($bytes / 1KB)) } return ('{0} bytes' -f $bytes) } function Clear-Folder([string]$Path) { $freed = [int64]0 $n = 0 if (-not (Test-Path -LiteralPath $Path)) { return @{ Freed = [int64]0; Files = 0 } } $children = @(Get-ChildItem -LiteralPath $Path -Force -ErrorAction SilentlyContinue) foreach ($item in $children) { if ($item.Name -like 'Honesty-Speed*') { continue } $bytes = [int64]0 if (-not $item.PSIsContainer) { $bytes = [int64]$item.Length } else { $files = @(Get-ChildItem -LiteralPath $item.FullName -Recurse -Force -File -ErrorAction SilentlyContinue) foreach ($file in $files) { $bytes += [int64]$file.Length } } if ($script:reportOnly) { $freed += $bytes $n += 1 continue } try { Remove-Item -LiteralPath $item.FullName -Recurse -Force -ErrorAction Stop $freed += $bytes $n += 1 } catch {} } return @{ Freed = $freed; Files = $n } } function Add-Clean([string]$label, [string]$path) { if ([string]::IsNullOrWhiteSpace($path)) { return } $result = Clear-Folder $path if ([int]$result.Files -eq 0) { Add-Row $label 'Nothing to clean' return } $verb = if ($script:reportOnly) { 'ready to remove' } else { 'removed' } Add-Row $label ("{0} {1} ({2} items)" -f (Format-Size ([int64]$result.Freed)), $verb, $result.Files) $script:total += [int64]$result.Freed } function Add-Clean-Mask([string]$label, [string]$mask) { $dirs = @(Get-Item -Path $mask -ErrorAction SilentlyContinue) if ($dirs.Count -eq 0) { Add-Row $label 'Nothing to clean' return } foreach ($dir in $dirs) { Add-Clean $label $dir.FullName } } function Clear-MatchingFiles([string]$label, [string]$mask) { $freed = [int64]0 $n = 0 $files = @(Get-ChildItem -Path $mask -Force -ErrorAction SilentlyContinue) foreach ($file in $files) { $bytes = [int64]$file.Length if ($script:reportOnly) { $freed += $bytes $n += 1 continue } try { Remove-Item -LiteralPath $file.FullName -Force -ErrorAction Stop $freed += $bytes $n += 1 } catch {} } if ($n -eq 0) { Add-Row $label 'Nothing to clean' return } $verb = if ($script:reportOnly) { 'ready to remove' } else { 'removed' } Add-Row $label ("{0} {1} ({2} files)" -f (Format-Size $freed), $verb, $n) $script:total += $freed } Write-Host 'Honesty Speed' if ($script:reportOnly) { Write-Host 'Report only. Nothing will be deleted.' } else { Write-Host 'Cleaning temporary files. Programs, photos, documents, and passwords stay.' } Write-Host '' $before = @(Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue | ForEach-Object { '{0} {1:N0} MB free' -f $_.DeviceID, ($_.FreeSpace / 1MB) }) $beforeText = if ($before.Count -eq 0) { 'Could not read the disks' } else { $before -join '; ' } $lowDisk = @(Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue | Where-Object { $_.FreeSpace -lt 15GB } | ForEach-Object { '{0} has {1:N1} GB free' -f $_.DeviceID, ($_.FreeSpace / 1GB) }) if ($lowDisk.Count -gt 0) { Add-Row 'Disk space' (($lowDisk -join '; ') + '. A full disk makes Windows slow. Cleanup removes temporary files. Photos, downloads, and old installers may still need to be moved off this disk.') } Add-Clean 'User temporary files' $env:TEMP if ($env:LOCALAPPDATA) { Add-Clean 'Delivery Optimization cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\DeliveryOptimization\Cache') Add-Clean-Mask 'Chrome cache' (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\*\Cache') Add-Clean-Mask 'Chrome code cache' (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\*\Code Cache') Add-Clean-Mask 'Chrome graphics cache' (Join-Path $env:LOCALAPPDATA 'Google\Chrome\User Data\*\GPUCache') Add-Clean-Mask 'Edge cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data\*\Cache') Add-Clean-Mask 'Edge code cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data\*\Code Cache') Add-Clean-Mask 'Edge graphics cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Edge\User Data\*\GPUCache') Add-Clean-Mask 'Brave cache' (Join-Path $env:LOCALAPPDATA 'BraveSoftware\Brave-Browser\User Data\*\Cache') Add-Clean-Mask 'Firefox cache' (Join-Path $env:LOCALAPPDATA 'Mozilla\Firefox\Profiles\*\cache2') Clear-MatchingFiles 'Thumbnail cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\Explorer\thumbcache_*.db') Add-Clean 'Error reports' (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\WER') Add-Clean 'Crash dumps' (Join-Path $env:LOCALAPPDATA 'CrashDumps') Add-Clean 'Old web cache' (Join-Path $env:LOCALAPPDATA 'Microsoft\Windows\INetCache') } $admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if ($admin) { Add-Clean 'Windows temporary files' 'C:\Windows\Temp' } else { Add-Row 'Windows temporary files' 'Skipped. Run the file as administrator to clean those.' } if ($script:reportOnly) { Add-Row 'Recycle Bin' 'Not emptied. This was a report.' Add-Row 'DNS cache' 'Not flushed. This was a report.' } else { try { Clear-RecycleBin -Force -ErrorAction Stop Add-Row 'Recycle Bin' 'Emptied' } catch { Add-Row 'Recycle Bin' 'Left as-is. It was already empty, or Windows kept it.' } $dns = ipconfig /flushdns | Out-String if ($dns -match 'Successfully') { Add-Row 'DNS cache' 'Flushed' } else { Add-Row 'DNS cache' $dns.Trim() } } $starts = @(Get-CimInstance Win32_StartupCommand -ErrorAction SilentlyContinue | ForEach-Object { '{0} — {1}' -f $_.Name, $_.Command }) if ($starts.Count -eq 0) { Add-Row 'Programs that start with Windows' 'None found' } else { Add-Row 'Programs that start with Windows' ($starts -join ' | ') } Add-Row 'Startup note' 'These were listed only. Nothing was turned off.' $scheme = (powercfg /getactivescheme | Out-String).Trim() Add-Row 'Power plan before' $scheme if ($script:reportOnly) { Add-Row 'Power plan' 'Left unchanged. This was a report.' } else { Write-Host '' Write-Host 'High performance stops Windows from slowing the processor to save power.' $answer = Read-Host 'Switch to High performance? Type Y or N' if ($answer -match '^[Yy]') { powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c | Out-Null if ($LASTEXITCODE -eq 0) { Add-Row 'Power plan' 'Switched to High performance' } else { Add-Row 'Power plan' 'Could not switch. This PC may not have that plan.' } } else { Add-Row 'Power plan' 'Left unchanged' } } $after = @(Get-CimInstance Win32_LogicalDisk -Filter 'DriveType=3' -ErrorAction SilentlyContinue | ForEach-Object { '{0} {1:N0} MB free' -f $_.DeviceID, ($_.FreeSpace / 1MB) }) $afterText = if ($after.Count -eq 0) { 'Could not read the disks' } else { $after -join '; ' } $totalLabel = Format-Size ([int64]$script:total) $rowHtml = $script:rows -join '' $action = if ($script:reportOnly) { 'counted, not removed' } else { 'removed' } $html = @" Honesty Speed report

Honesty Speed

Temporary files were $action. Programs, photos, documents, and saved passwords were left alone. Startup programs were listed and not turned off.

$totalLabel of temporary files $action.

Disk before: $(Esc $beforeText)

Disk after: $(Esc $afterText)

$rowHtml

Still slow? Call Honesty Support at 1-888-711-9954 or open https://honestysupport.com/it

"@ $report = Join-Path $env:TEMP 'Honesty-Speed-Report.html' Set-Content -LiteralPath $report -Value $html -Encoding UTF8 Write-Host '' Write-Host ("{0} of temporary files {1}." -f $totalLabel, $action) Write-Host 'Opening the report in your browser.' Start-Process $report