Advertisement
bluethefox

JDI

Apr 21st, 2025
421
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. .SYNOPSIS
  3.     Just Delete It - A PowerShell tool to free up disk space by safely removing temporary and system files.
  4. .DESCRIPTION
  5.     This script cleans various system and temporary folders to reclaim disk space without affecting user files.
  6.     It shows detailed progress for each operation and works with Windows 10/11.
  7.     Run as administrator for best results.
  8. .NOTES
  9.     Version: 2.0
  10. #>
  11.  
  12. # Suppress non-critical errors and warnings
  13. $ErrorActionPreference = "SilentlyContinue"
  14. $WarningPreference = "SilentlyContinue"
  15.  
  16. # Function for colored console output
  17. function Write-ColorOutput {
  18.     param (
  19.         [string]$Message,
  20.         [string]$ForegroundColor = "White"
  21.     )
  22.    
  23.     $originalColor = $host.UI.RawUI.ForegroundColor
  24.     $host.UI.RawUI.ForegroundColor = $ForegroundColor
  25.     Write-Output $Message
  26.     $host.UI.RawUI.ForegroundColor = $originalColor
  27. }
  28.  
  29. # Function to get folder size
  30. function Get-FolderSize {
  31.     param (
  32.         [string]$Path
  33.     )
  34.    
  35.     if (Test-Path -Path $Path) {
  36.         $size = (Get-ChildItem -Path $Path -Recurse -Force | Measure-Object -Property Length -Sum).Sum
  37.         return $size
  38.     }
  39.     return 0
  40. }
  41.  
  42. # Function to format file size in human-readable format
  43. function Format-FileSize {
  44.     param (
  45.         [long]$Size
  46.     )
  47.    
  48.     if ($Size -ge 1TB) {
  49.         return "{0:N2} TB" -f ($Size / 1TB)
  50.     }
  51.     elseif ($Size -ge 1GB) {
  52.         return "{0:N2} GB" -f ($Size / 1GB)
  53.     }
  54.     elseif ($Size -ge 1MB) {
  55.         return "{0:N2} MB" -f ($Size / 1MB)
  56.     }
  57.     elseif ($Size -ge 1KB) {
  58.         return "{0:N2} KB" -f ($Size / 1KB)
  59.     }
  60.     else {
  61.         return "$Size Bytes"
  62.     }
  63. }
  64.  
  65. # Function to clean Windows temporary folders
  66. function Clear-WindowsTemp {
  67.     Write-ColorOutput "Cleaning Windows Temp Folders..." -ForegroundColor Cyan
  68.    
  69.     $totalReclaimed = 0
  70.     $locations = @{
  71.         "Windows Temp" = "$env:windir\Temp";
  72.         "User Temp" = "$env:TEMP";
  73.         "System Temp" = "$env:SystemRoot\Temp";
  74.         "Prefetch" = "$env:windir\Prefetch";
  75.         "Windows Error Reports" = "$env:LOCALAPPDATA\Microsoft\Windows\WER";
  76.         "Internet Explorer Cache" = "$env:LOCALAPPDATA\Microsoft\Windows\INetCache";
  77.         "Setup Log Files" = "$env:windir\Logs"
  78.     }
  79.    
  80.     foreach ($location in $locations.GetEnumerator()) {
  81.         $name = $location.Key
  82.         $path = $location.Value
  83.        
  84.         Write-ColorOutput "  Processing $name..." -ForegroundColor Gray
  85.        
  86.         if (Test-Path -Path $path) {
  87.             $initialSize = Get-FolderSize -Path $path
  88.             Write-ColorOutput "  Size before cleanup: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  89.            
  90.             # Clean files
  91.             Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer } | ForEach-Object {
  92.                 try {
  93.                     Remove-Item -Path $_.FullName -Force
  94.                     Write-Progress -Activity "Cleaning $name" -Status "Removing $($_.Name)" -PercentComplete -1
  95.                 } catch {}
  96.             }
  97.            
  98.             # Clean empty folders
  99.             Get-ChildItem -Path $path -Recurse -Force -Directory |
  100.                 Where-Object { (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }).Count -eq 0 } |
  101.                 Sort-Object -Property FullName -Descending |
  102.                 ForEach-Object {
  103.                     try {
  104.                         Remove-Item -Path $_.FullName -Force -Recurse
  105.                     } catch {}
  106.                 }
  107.            
  108.             $newSize = Get-FolderSize -Path $path
  109.             $reclaimed = $initialSize - $newSize
  110.             $totalReclaimed += $reclaimed
  111.            
  112.             Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  113.         }
  114.         else {
  115.             Write-ColorOutput "  Folder not found" -ForegroundColor Yellow
  116.         }
  117.     }
  118.    
  119.     Write-Progress -Activity "Cleaning Temp Folders" -Completed
  120.     return $totalReclaimed
  121. }
  122.  
  123. # Function to clean Windows Update cache
  124. function Clear-WindowsUpdateCache {
  125.     Write-ColorOutput "Cleaning Windows Update Cache..." -ForegroundColor Cyan
  126.    
  127.     try {
  128.         # Stop Windows Update service
  129.         Stop-Service -Name wuauserv -Force
  130.        
  131.         $updatePath = "$env:windir\SoftwareDistribution\Download"
  132.         $initialSize = Get-FolderSize -Path $updatePath
  133.        
  134.         Write-ColorOutput "  Size before cleanup: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  135.        
  136.         # Delete contents
  137.         Get-ChildItem -Path "$updatePath\*" -Recurse -Force | ForEach-Object {
  138.             try {
  139.                 Remove-Item -Path $_.FullName -Force -Recurse
  140.                 Write-Progress -Activity "Cleaning Windows Update Cache" -Status "Removing $($_.Name)" -PercentComplete -1
  141.             } catch {}
  142.         }
  143.        
  144.         # Restart service
  145.         Start-Service -Name wuauserv
  146.        
  147.         $newSize = Get-FolderSize -Path $updatePath
  148.         $reclaimed = $initialSize - $newSize
  149.        
  150.         Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  151.         Write-Progress -Activity "Cleaning Windows Update Cache" -Completed
  152.         return $reclaimed
  153.     } catch {
  154.         Write-ColorOutput "  Error cleaning Windows Update Cache" -ForegroundColor Yellow
  155.         return 0
  156.     }
  157. }
  158.  
  159. # Function to clean browser caches
  160. function Clear-BrowserCaches {
  161.     Write-ColorOutput "Cleaning Browser Caches..." -ForegroundColor Cyan
  162.    
  163.     $totalReclaimed = 0
  164.    
  165.     # Chrome
  166.     $chromeCachePath = "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache"
  167.     if (Test-Path -Path $chromeCachePath) {
  168.         $initialSize = Get-FolderSize -Path $chromeCachePath
  169.         Write-ColorOutput "  Chrome Cache: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  170.        
  171.         Get-ChildItem -Path $chromeCachePath -Recurse -Force | ForEach-Object {
  172.             try {
  173.                 Remove-Item -Path $_.FullName -Force -Recurse
  174.                 Write-Progress -Activity "Cleaning Chrome Cache" -Status "Removing $($_.Name)" -PercentComplete -1
  175.             } catch {}
  176.         }
  177.        
  178.         $newSize = Get-FolderSize -Path $chromeCachePath
  179.         $reclaimed = $initialSize - $newSize
  180.         $totalReclaimed += $reclaimed
  181.        
  182.         Write-ColorOutput "  Chrome space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  183.     }
  184.    
  185.     # Firefox
  186.     $firefoxProfiles = "$env:APPDATA\Mozilla\Firefox\Profiles"
  187.     if (Test-Path -Path $firefoxProfiles) {
  188.         $profiles = Get-ChildItem -Path $firefoxProfiles -Directory
  189.        
  190.         foreach ($profile in $profiles) {
  191.             $cachePath = Join-Path -Path $profile.FullName -ChildPath "cache2"
  192.            
  193.             if (Test-Path -Path $cachePath) {
  194.                 $initialSize = Get-FolderSize -Path $cachePath
  195.                 Write-ColorOutput "  Firefox Cache: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  196.                
  197.                 Get-ChildItem -Path $cachePath -Recurse -Force | ForEach-Object {
  198.                     try {
  199.                         Remove-Item -Path $_.FullName -Force -Recurse
  200.                         Write-Progress -Activity "Cleaning Firefox Cache" -Status "Removing $($_.Name)" -PercentComplete -1
  201.                     } catch {}
  202.                 }
  203.                
  204.                 $newSize = Get-FolderSize -Path $cachePath
  205.                 $reclaimed = $initialSize - $newSize
  206.                 $totalReclaimed += $reclaimed
  207.                
  208.                 Write-ColorOutput "  Firefox space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  209.             }
  210.         }
  211.     }
  212.    
  213.     # Edge
  214.     $edgeCachePath = "$env:LOCALAPPDATA\Microsoft\Edge\User Data\Default\Cache"
  215.     if (Test-Path -Path $edgeCachePath) {
  216.         $initialSize = Get-FolderSize -Path $edgeCachePath
  217.         Write-ColorOutput "  Edge Cache: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  218.        
  219.         Get-ChildItem -Path $edgeCachePath -Recurse -Force | ForEach-Object {
  220.             try {
  221.                 Remove-Item -Path $_.FullName -Force -Recurse
  222.                 Write-Progress -Activity "Cleaning Edge Cache" -Status "Removing $($_.Name)" -PercentComplete -1
  223.             } catch {}
  224.         }
  225.        
  226.         $newSize = Get-FolderSize -Path $edgeCachePath
  227.         $reclaimed = $initialSize - $newSize
  228.         $totalReclaimed += $reclaimed
  229.        
  230.         Write-ColorOutput "  Edge space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  231.     }
  232.    
  233.     # Brave
  234.     $braveCachePath = "$env:LOCALAPPDATA\BraveSoftware\Brave-Browser\User Data\Default\Cache"
  235.     if (Test-Path -Path $braveCachePath) {
  236.         $initialSize = Get-FolderSize -Path $braveCachePath
  237.         Write-ColorOutput "  Brave Cache: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  238.        
  239.         Get-ChildItem -Path $braveCachePath -Recurse -Force | ForEach-Object {
  240.             try {
  241.                 Remove-Item -Path $_.FullName -Force -Recurse
  242.                 Write-Progress -Activity "Cleaning Brave Cache" -Status "Removing $($_.Name)" -PercentComplete -1
  243.             } catch {}
  244.         }
  245.        
  246.         $newSize = Get-FolderSize -Path $braveCachePath
  247.         $reclaimed = $initialSize - $newSize
  248.         $totalReclaimed += $reclaimed
  249.        
  250.         Write-ColorOutput "  Brave space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  251.     }
  252.    
  253.     Write-Progress -Activity "Cleaning Browser Caches" -Completed
  254.     return $totalReclaimed
  255. }
  256.  
  257. # Function to empty Recycle Bin
  258. function Empty-RecycleBin {
  259.     Write-ColorOutput "Emptying Recycle Bin..." -ForegroundColor Cyan
  260.    
  261.     try {
  262.         # Get Recycle Bin size
  263.         $shell = New-Object -ComObject Shell.Application
  264.         $recycleBin = $shell.Namespace(0xA)
  265.         $recycleBinSize = 0
  266.        
  267.         foreach ($item in $recycleBin.Items()) {
  268.             $recycleBinSize += $item.Size
  269.         }
  270.        
  271.         Write-ColorOutput "  Recycle Bin size: $(Format-FileSize -Size $recycleBinSize)" -ForegroundColor Gray
  272.        
  273.         # Empty Recycle Bin
  274.         Write-Progress -Activity "Emptying Recycle Bin" -Status "Please wait..." -PercentComplete 50
  275.         Clear-RecycleBin -Force
  276.        
  277.         Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $recycleBinSize)" -ForegroundColor Green
  278.         Write-Progress -Activity "Emptying Recycle Bin" -Completed
  279.         return $recycleBinSize
  280.     } catch {
  281.         Write-ColorOutput "  Error emptying Recycle Bin" -ForegroundColor Yellow
  282.         return 0
  283.     }
  284. }
  285.  
  286. # Function to clean up old Windows versions (Windows.old)
  287. function Remove-OldWindowsVersions {
  288.     Write-ColorOutput "Cleaning Old Windows Versions..." -ForegroundColor Cyan
  289.    
  290.     try {
  291.         $oldWindowsPath = "$env:SystemDrive\Windows.old"
  292.         if (Test-Path -Path $oldWindowsPath) {
  293.             $initialSize = Get-FolderSize -Path $oldWindowsPath
  294.             Write-ColorOutput "  Windows.old size: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  295.            
  296.             # Run disk cleanup tool
  297.             Write-Progress -Activity "Running Disk Cleanup" -Status "Please wait..." -PercentComplete 50
  298.             Start-Process -FilePath "cleanmgr.exe" -ArgumentList "/sagerun:65535" -Wait
  299.            
  300.             if (Test-Path -Path $oldWindowsPath) {
  301.                 $newSize = Get-FolderSize -Path $oldWindowsPath
  302.                 $reclaimed = $initialSize - $newSize
  303.                 Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  304.                 Write-Progress -Activity "Cleaning Old Windows Versions" -Completed
  305.                 return $reclaimed
  306.             } else {
  307.                 Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $initialSize)" -ForegroundColor Green
  308.                 Write-Progress -Activity "Cleaning Old Windows Versions" -Completed
  309.                 return $initialSize
  310.             }
  311.         } else {
  312.             Write-ColorOutput "  No old Windows installation found" -ForegroundColor Gray
  313.             return 0
  314.         }
  315.     } catch {
  316.         Write-ColorOutput "  Error cleaning old Windows versions" -ForegroundColor Yellow
  317.         return 0
  318.     }
  319. }
  320.  
  321. # Function to clean Windows Event Logs
  322. function Clear-EventLogs {
  323.     Write-ColorOutput "Clearing Windows Event Logs..." -ForegroundColor Cyan
  324.    
  325.     try {
  326.         $eventLogs = Get-WinEvent -ListLog * -ErrorAction SilentlyContinue | Where-Object { $_.RecordCount -gt 0 }
  327.         $totalSize = 0
  328.         $i = 0
  329.        
  330.         foreach ($log in $eventLogs) {
  331.             $i++
  332.             $percentage = [math]::Min(100, ($i / $eventLogs.Count) * 100)
  333.            
  334.             try {
  335.                 Write-Progress -Activity "Clearing Event Logs" -Status "Processing $($log.LogName)" -PercentComplete $percentage
  336.                
  337.                 # Get log file path and size
  338.                 $logName = $log.LogName
  339.                 $logPath = "$env:windir\System32\winevt\Logs\$($logName -replace "/", "-").evtx"
  340.                
  341.                 if (Test-Path -Path $logPath) {
  342.                     $logSize = (Get-Item -Path $logPath).Length
  343.                     $totalSize += $logSize
  344.                    
  345.                     # Clear log if it's large enough
  346.                     if ($logSize -gt 1MB) {
  347.                         [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog($logName)
  348.                         Write-ColorOutput "  Cleared log: $($logName -replace "/", "-")" -ForegroundColor Gray
  349.                     }
  350.                 }
  351.             } catch {}
  352.         }
  353.        
  354.         Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $totalSize)" -ForegroundColor Green
  355.         Write-Progress -Activity "Clearing Event Logs" -Completed
  356.         return $totalSize
  357.     } catch {
  358.         Write-ColorOutput "  Error clearing event logs" -ForegroundColor Yellow
  359.         return 0
  360.     }
  361. }
  362.  
  363. # Function to clean Windows Defender logs and history
  364. function Clear-DefenderHistory {
  365.     Write-ColorOutput "Cleaning Windows Defender History..." -ForegroundColor Cyan
  366.    
  367.     try {
  368.         $defenderPath = "$env:ProgramData\Microsoft\Windows Defender\Scans\History"
  369.         if (Test-Path -Path $defenderPath) {
  370.             $initialSize = Get-FolderSize -Path $defenderPath
  371.             Write-ColorOutput "  Defender history size: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  372.            
  373.             # Remove history files
  374.             Get-ChildItem -Path $defenderPath -Recurse -Force | ForEach-Object {
  375.                 try {
  376.                     Remove-Item -Path $_.FullName -Force -Recurse
  377.                     Write-Progress -Activity "Cleaning Defender History" -Status "Removing $($_.Name)" -PercentComplete -1
  378.                 } catch {}
  379.             }
  380.            
  381.             $newSize = Get-FolderSize -Path $defenderPath
  382.             $reclaimed = $initialSize - $newSize
  383.            
  384.             Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  385.             Write-Progress -Activity "Cleaning Defender History" -Completed
  386.             return $reclaimed
  387.         } else {
  388.             Write-ColorOutput "  Defender history folder not found" -ForegroundColor Yellow
  389.             return 0
  390.         }
  391.     } catch {
  392.         Write-ColorOutput "  Error cleaning Defender history" -ForegroundColor Yellow
  393.         return 0
  394.     }
  395. }
  396.  
  397. # Function to clean Delivery Optimization files
  398. function Clear-DeliveryOptimization {
  399.     Write-ColorOutput "Cleaning Delivery Optimization Cache..." -ForegroundColor Cyan
  400.    
  401.     try {
  402.         # Stop Delivery Optimization service
  403.         Stop-Service -Name DoSvc -Force
  404.        
  405.         $doPath = "$env:windir\ServiceProfiles\NetworkService\AppData\Local\Microsoft\Windows\DeliveryOptimization\Cache"
  406.         if (Test-Path -Path $doPath) {
  407.             $initialSize = Get-FolderSize -Path $doPath
  408.             Write-ColorOutput "  Delivery Optimization size: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  409.            
  410.             # Remove cache files
  411.             Get-ChildItem -Path "$doPath\*" -Recurse -Force | ForEach-Object {
  412.                 try {
  413.                     Remove-Item -Path $_.FullName -Force -Recurse
  414.                     Write-Progress -Activity "Cleaning Delivery Optimization" -Status "Removing $($_.Name)" -PercentComplete -1
  415.                 } catch {}
  416.             }
  417.            
  418.             # Start service
  419.             Start-Service -Name DoSvc
  420.            
  421.             $newSize = Get-FolderSize -Path $doPath
  422.             $reclaimed = $initialSize - $newSize
  423.            
  424.             Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  425.             Write-Progress -Activity "Cleaning Delivery Optimization" -Completed
  426.             return $reclaimed
  427.         } else {
  428.             # Start service
  429.             Start-Service -Name DoSvc
  430.             Write-ColorOutput "  Delivery Optimization folder not found" -ForegroundColor Yellow
  431.             return 0
  432.         }
  433.     } catch {
  434.         # Start service
  435.         Start-Service -Name DoSvc
  436.         Write-ColorOutput "  Error cleaning Delivery Optimization" -ForegroundColor Yellow
  437.         return 0
  438.     }
  439. }
  440.  
  441. # Function to clean thumbnails cache
  442. function Clear-ThumbnailCache {
  443.     Write-ColorOutput "Cleaning Thumbnail Cache..." -ForegroundColor Cyan
  444.    
  445.     try {
  446.         $thumbCachePath = "$env:LOCALAPPDATA\Microsoft\Windows\Explorer"
  447.         $thumbCacheFiles = Get-ChildItem -Path $thumbCachePath -Filter "thumbcache_*.db" -Force
  448.        
  449.         $initialSize = 0
  450.         foreach ($file in $thumbCacheFiles) {
  451.             $initialSize += $file.Length
  452.         }
  453.        
  454.         Write-ColorOutput "  Thumbnail cache size: $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  455.        
  456.         # Remove thumbnail cache files
  457.         foreach ($file in $thumbCacheFiles) {
  458.             try {
  459.                 Remove-Item -Path $file.FullName -Force
  460.                 Write-Progress -Activity "Cleaning Thumbnail Cache" -Status "Removing $($file.Name)" -PercentComplete -1
  461.             } catch {}
  462.         }
  463.        
  464.         Write-ColorOutput "  Space reclaimed: $(Format-FileSize -Size $initialSize)" -ForegroundColor Green
  465.         Write-Progress -Activity "Cleaning Thumbnail Cache" -Completed
  466.         return $initialSize
  467.     } catch {
  468.         Write-ColorOutput "  Error cleaning thumbnail cache" -ForegroundColor Yellow
  469.         return 0
  470.     }
  471. }
  472.  
  473. # Function to clean user temporary files
  474. function Clear-UserTemp {
  475.     Write-ColorOutput "Cleaning User Temp Files..." -ForegroundColor Cyan
  476.    
  477.     $totalReclaimed = 0
  478.    
  479.     # Get all user profiles
  480.     $userProfiles = Get-ChildItem -Path "C:\Users" -Directory
  481.    
  482.     foreach ($profile in $userProfiles) {
  483.         $tempPath = Join-Path -Path $profile.FullName -ChildPath "AppData\Local\Temp"
  484.        
  485.         if (Test-Path -Path $tempPath) {
  486.             $initialSize = Get-FolderSize -Path $tempPath
  487.             Write-ColorOutput "  Temp folder for $($profile.Name): $(Format-FileSize -Size $initialSize)" -ForegroundColor Gray
  488.            
  489.             # Delete files older than 7 days
  490.             $cutoffDate = (Get-Date).AddDays(-7)
  491.             Get-ChildItem -Path $tempPath -Recurse -Force | Where-Object {
  492.                 !$_.PSIsContainer -and $_.LastWriteTime -lt $cutoffDate
  493.             } | ForEach-Object {
  494.                 try {
  495.                     Remove-Item -Path $_.FullName -Force
  496.                     Write-Progress -Activity "Cleaning User Temp Files" -Status "Removing $($_.Name)" -PercentComplete -1
  497.                 } catch {}
  498.             }
  499.            
  500.             # Remove empty folders
  501.             Get-ChildItem -Path $tempPath -Recurse -Force -Directory |
  502.                 Where-Object { (Get-ChildItem -Path $_.FullName -Recurse -Force | Where-Object { !$_.PSIsContainer }).Count -eq 0 } |
  503.                 Sort-Object -Property FullName -Descending |
  504.                 ForEach-Object {
  505.                     try {
  506.                         Remove-Item -Path $_.FullName -Force -Recurse
  507.                     } catch {}
  508.                 }
  509.            
  510.             $newSize = Get-FolderSize -Path $tempPath
  511.             $reclaimed = $initialSize - $newSize
  512.             $totalReclaimed += $reclaimed
  513.            
  514.             Write-ColorOutput "  Space reclaimed for $($profile.Name): $(Format-FileSize -Size $reclaimed)" -ForegroundColor Green
  515.         }
  516.     }
  517.    
  518.     Write-Progress -Activity "Cleaning User Temp Files" -Completed
  519.     return $totalReclaimed
  520. }
  521.  
  522. # Main script execution
  523.  
  524. # Check for admin rights
  525. $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  526.  
  527. Clear-Host
  528. Write-ColorOutput "=========================================" -ForegroundColor Cyan
  529. Write-ColorOutput "           JUST DELETE IT v2.0          " -ForegroundColor Cyan
  530. Write-ColorOutput "     Windows System Cleanup Utility     " -ForegroundColor Cyan
  531. Write-ColorOutput "=========================================" -ForegroundColor Cyan
  532. Write-Output ""
  533.  
  534. if (-not $isAdmin) {
  535.     Write-ColorOutput "WARNING: Not running as Administrator. Some cleanup operations may fail." -ForegroundColor Yellow
  536.     Write-ColorOutput "For best results, please run this script as Administrator." -ForegroundColor Yellow
  537.     Write-Output ""
  538. }
  539.  
  540. $startTime = Get-Date
  541. $totalSpaceReclaimed = 0
  542.  
  543. # Get initial free space
  544. $drive = Get-PSDrive -Name C
  545. $initialFreeSpace = $drive.Free
  546. $initialFreeSpaceFormatted = Format-FileSize -Size $initialFreeSpace
  547.  
  548. Write-ColorOutput "Initial free space: $initialFreeSpaceFormatted" -ForegroundColor Magenta
  549. Write-Output ""
  550.  
  551. # Run cleanup operations
  552. $tempSize = Clear-WindowsTemp
  553. $totalSpaceReclaimed += $tempSize
  554. Write-Output ""
  555.  
  556. $updateSize = Clear-WindowsUpdateCache
  557. $totalSpaceReclaimed += $updateSize
  558. Write-Output ""
  559.  
  560. $browserSize = Clear-BrowserCaches
  561. $totalSpaceReclaimed += $browserSize
  562. Write-Output ""
  563.  
  564. $recycleBinSize = Empty-RecycleBin
  565. $totalSpaceReclaimed += $recycleBinSize
  566. Write-Output ""
  567.  
  568. $oldWindowsSize = Remove-OldWindowsVersions
  569. $totalSpaceReclaimed += $oldWindowsSize
  570. Write-Output ""
  571.  
  572. $eventLogSize = Clear-EventLogs
  573. $totalSpaceReclaimed += $eventLogSize
  574. Write-Output ""
  575.  
  576. $defenderSize = Clear-DefenderHistory
  577. $totalSpaceReclaimed += $defenderSize
  578. Write-Output ""
  579.  
  580. $doSize = Clear-DeliveryOptimization
  581. $totalSpaceReclaimed += $doSize
  582. Write-Output ""
  583.  
  584. $thumbSize = Clear-ThumbnailCache
  585. $totalSpaceReclaimed += $thumbSize
  586. Write-Output ""
  587.  
  588. $userTempSize = Clear-UserTemp
  589. $totalSpaceReclaimed += $userTempSize
  590. Write-Output ""
  591.  
  592. # Get final free space
  593. $drive = Get-PSDrive -Name C
  594. $finalFreeSpace = $drive.Free
  595. $finalFreeSpaceFormatted = Format-FileSize -Size $finalFreeSpace
  596. $actualReclaimed = $finalFreeSpace - $initialFreeSpace
  597. $actualReclaimedFormatted = Format-FileSize -Size $actualReclaimed
  598.  
  599. $endTime = Get-Date
  600. $duration = $endTime - $startTime
  601. $durationFormatted = "{0:hh\:mm\:ss}" -f $duration
  602.  
  603. Write-ColorOutput "=========================================" -ForegroundColor Cyan
  604. Write-ColorOutput "               SUMMARY                   " -ForegroundColor Cyan
  605. Write-ColorOutput "=========================================" -ForegroundColor Cyan
  606. Write-Output ""
  607. Write-ColorOutput "Operation completed in $durationFormatted" -ForegroundColor Magenta
  608. Write-ColorOutput "Initial free space: $initialFreeSpaceFormatted" -ForegroundColor Magenta
  609. Write-ColorOutput "Current free space: $finalFreeSpaceFormatted" -ForegroundColor Magenta
  610. Write-ColorOutput "Total space reclaimed: $actualReclaimedFormatted" -ForegroundColor Green
  611. Write-Output ""
  612. Write-ColorOutput "Just Delete It has completed successfully!" -ForegroundColor Cyan
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement