diff --git a/bleachbit.ps1 b/bleachbit.ps1 index 82728cb..31365c1 100644 --- a/bleachbit.ps1 +++ b/bleachbit.ps1 @@ -1,10 +1,8 @@ # BleachBit Script # Downloads BleachBit portable, extracts it, and runs the cleanup command - param( [string]$InstallPath = "C:\Quest" ) - $BleachBitCleaners = @( "adobe_reader.cache", "adobe_reader.mru", "adobe_reader.tmp", "amule.known_clients", "amule.known_files", "amule.logs", "amule.temp", @@ -45,7 +43,6 @@ $BleachBitCleaners = @( "yahoo_messenger.cache", "yahoo_messenger.chat_logs", "yahoo_messenger.logs", "zoom.cache", "zoom.logs" ) - Write-Host "Stopping Edge processes..." try { $EdgeProcesses = Get-Process -Name "*Edge*" -ErrorAction SilentlyContinue @@ -58,37 +55,43 @@ try { } catch { Write-Host "Warning: Could not stop Edge processes: $($_.Exception.Message)" } - $DownloadURL = "https://download.bleachbit.org/BleachBit-5.0.2-portable.zip" $zipPath = "$InstallPath\BleachBit.zip" $exePath = "$InstallPath\BleachBit-Portable\bleachbit_console.exe" - # Create directory if it doesn't exist if (-not (Test-Path $InstallPath)) { New-Item -Path $InstallPath -ItemType Directory -Force | Out-Null } - # Download if not exists if (-not (Test-Path $zipPath)) { Write-Host "Downloading BleachBit..." Invoke-WebRequest -Uri $DownloadURL -OutFile $zipPath -UseBasicParsing } - # Extract if exe doesn't exist if (-not (Test-Path $exePath)) { Write-Host "Extracting BleachBit..." Expand-Archive -Path $zipPath -DestinationPath $InstallPath -Force } - -# Run the cleanup command +# Run the cleanup command and capture output Write-Host "Running BleachBit cleanup..." -$CleanerArgs = $BleachBitCleaners -join " " -$output = Start-Process -FilePath $exePath -ArgumentList "--clean $CleanerArgs" -NoNewWindow -Wait -PassThru -ErrorAction Stop + +try { + # Use call operator (&) to capture output instead of Start-Process + $output = & $exePath --clean $CleanerArgs 2>&1 + + # Convert output to string + $outputText = $output | Out-String + + Write-Host $outputText +} catch { + $outputText = "Error running BleachBit: $($_.Exception.Message)" + Write-Host $outputText +} # Output JSON result $result = @{ success = $true - output = $output + output = $outputText } | ConvertTo-Json -Compress Write-Output $result \ No newline at end of file