# ============================================================ # CLEANUP ULTRA – WITH COLORED HTML LOG (UTF8) # ============================================================ $global:HtmlLog = "$env:SystemDrive\CleanupUltra-Log.html" # --- HTML Header --- @" Cleanup Ultra Log

Cleanup Ultra Log – $(Get-Date)

"@ | Out-File -FilePath $global:HtmlLog -Encoding utf8 function Write-LogHtml { param([string]$Message, [string]$Class) "
$Message
" | Out-File -FilePath $global:HtmlLog -Append -Encoding utf8 } # --- Disk space before --- $before = (Get-PSDrive C).Free Write-LogHtml "Free before: $([math]::Round($before/1GB,2)) GB" "info" # --- Safe delete function --- function Clear-ContentSafe { param([string]$Path) if (Test-Path $Path) { Get-ChildItem -Path $Path -Force -ErrorAction SilentlyContinue | ForEach-Object { $item = $_ if (-not $item.FullName -or $item.FullName.Trim().Length -eq 0) { return } try { Remove-Item -Path $item.FullName -Recurse -Force -ErrorAction Stop Write-LogHtml "OK: Removed $($item.FullName)" "ok" } catch { Write-LogHtml "SKIPPED (in use): $($item.FullName)" "skip" } } } } # ============================================================ # CLEANUP TARGETS # ============================================================ # --- User Temp --- Clear-ContentSafe "$env:LOCALAPPDATA\Temp" Clear-ContentSafe "$env:TEMP" # --- Windows Temp --- Clear-ContentSafe "C:\Windows\Temp" Clear-ContentSafe "C:\Windows\System32\Temp" Clear-ContentSafe "C:\Windows\assembly\Temp" # --- UWP App Temp --- $uwp = Get-ChildItem "$env:LOCALAPPDATA\Packages" -Directory -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.FullName -like "*\AC\Temp" } foreach ($folder in $uwp) { Clear-ContentSafe $folder.FullName } # --- Browser Caches --- Clear-ContentSafe "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache" Clear-ContentSafe "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Code Cache" Clear-ContentSafe "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache" Clear-ContentSafe "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Code Cache" $ff = Get-ChildItem "$env:APPDATA\Mozilla\Firefox\Profiles" -Directory -ErrorAction SilentlyContinue foreach ($profile in $ff) { Clear-ContentSafe "$($profile.FullName)\cache2" } # --- Office Caches --- Clear-ContentSafe "$env:LOCALAPPDATA\Microsoft\Office\16.0\OfficeFileCache" Clear-ContentSafe "$env:LOCALAPPDATA\Microsoft\OneDrive\logs" # --- Winget Cache --- Clear-ContentSafe "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\AC\Temp" Clear-ContentSafe "$env:LOCALAPPDATA\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalCache" # --- Delivery Optimization --- Clear-ContentSafe "C:\Windows\SoftwareDistribution\Download" # --- Crash Dumps --- Clear-ContentSafe "C:\Windows\Minidump" if (Test-Path "C:\Windows\MEMORY.DMP") { try { Remove-Item "C:\Windows\MEMORY.DMP" -Force Write-LogHtml "OK: Removed MEMORY.DMP" "ok" } catch { Write-LogHtml "SKIPPED (in use): MEMORY.DMP" "skip" } } # --- Steam Shader Cache --- Clear-ContentSafe "$env:LOCALAPPDATA\Steam\shadercache" Clear-ContentSafe "$env:LOCALAPPDATA\Steam\htmlcache" # ============================================================ # TW-*.TMP SYSTEMPROFILE CLEANUP # ============================================================ Write-LogHtml "Cleaning tw-*.tmp in SYSTEMPROFILE…" "info" $twPath = "C:\Windows\System32\config\systemprofile\AppData\Local" if (Test-Path $twPath) { Get-ChildItem -Path $twPath -Filter "tw-*.tmp" -Force -ErrorAction SilentlyContinue | ForEach-Object { $item = $_ try { Remove-Item -Path $item.FullName -Force -ErrorAction Stop Write-LogHtml "OK: Removed $($item.FullName)" "ok" } catch { Write-LogHtml "SKIPPED (in use): $($item.FullName)" "skip" } } } else { Write-LogHtml "SYSTEMPROFILE path not found" "skip" } # ============================================================ # DISM CLEANUP (SAFE) # ============================================================ Write-LogHtml "Running DISM component cleanup…" "info" dism /online /cleanup-image /startcomponentcleanup | Out-Null Write-LogHtml "DISM cleanup completed" "ok" # ============================================================ # Windows Update Cleanup (safe) # ============================================================ Write-LogHtml "Cleaning Windows Update leftovers…" "info" try { Remove-Item "C:\Windows\SoftwareDistribution\Download\*" -Recurse -Force -ErrorAction Stop Write-LogHtml "OK: Windows Update cache cleaned" "ok" } catch { Write-LogHtml "SKIPPED: Windows Update cache in use" "skip" } # ============================================================ # DISK SPACE AFTER # ============================================================ $after = (Get-PSDrive C).Free $diff = $after - $before Write-LogHtml "Free after: $([math]::Round($after/1GB,2)) GB" "info" Write-LogHtml "Freed: $([math]::Round($diff/1GB,2)) GB" "ok" # --- HTML Footer --- "" | Out-File -FilePath $global:HtmlLog -Append -Encoding utf8 # --- HTML Log automatisch öffnen --- Start-Process $global:HtmlLog Write-Host "Cleanup Ultra completed. HTML log saved to $global:HtmlLog"