#Requires -RunAsAdministrator <# .SYNOPSIS Nerdy Neighbor - Silent, complete uninstaller for Malwarebytes (Windows). .NOTES Run with: irm mbam-uninstall.nerdyneighbor.net | iex (elevated Windows PowerShell) Three passes, most-graceful first: 1. If the normal uninstaller (mbuns.exe) is present, run it silently with /NOSURVEY -> a clean product uninstall with NO survey prompt (that survey is the only reason the built-in uninstaller is annoying). 2. Always run Malwarebytes' official Support Tool in cleanup mode (mbst.exe /y /cleanup /noreboot) -> removes ALL Malwarebytes products and leftover files/services/registry keys. Never shows a survey. 3. Sweep any residual Malwarebytes folders as a final belt-and-suspenders. No reboot is forced. Everything is logged to C:\ProgramData\NerdyNeighbor\mbam-uninstall.log Exit code 0 = Malwarebytes gone, 1 = something still present / failed. #> $ErrorActionPreference = 'Stop' # --- Constants --------------------------------------------------------------- $SupportToolUrl = 'https://downloads.malwarebytes.com/file/mbst' # evergreen Support Tool $MbunsPath = Join-Path $env:ProgramFiles 'Malwarebytes\Anti-Malware\mbuns.exe' $MbunsArgs = '/VERYSILENT /NORESTART /NOSURVEY' $CleanupArgs = '/y /cleanup /noreboot' $LogDir = Join-Path $env:ProgramData 'NerdyNeighbor' $LogFile = Join-Path $LogDir 'mbam-uninstall.log' $Mbst = Join-Path $env:TEMP ('mbst-{0}.exe' -f (Get-Random)) $ResidualPaths = @( (Join-Path $env:ProgramFiles 'Malwarebytes'), (Join-Path ${env:ProgramFiles(x86)} 'Malwarebytes'), (Join-Path $env:ProgramData 'Malwarebytes') ) # --- Logging ----------------------------------------------------------------- if (-not (Test-Path $LogDir)) { New-Item -ItemType Directory -Path $LogDir -Force | Out-Null } function Write-Log { param([string]$Message, [string]$Level = 'INFO') $line = '{0} [{1}] {2}' -f (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'), $Level, $Message Add-Content -Path $LogFile -Value $line -ErrorAction SilentlyContinue switch ($Level) { 'ERROR' { Write-Host " $Message" -ForegroundColor Red } 'WARN' { Write-Host " $Message" -ForegroundColor Yellow } default { Write-Host " $Message" -ForegroundColor Gray } } } function Test-MalwarebytesPresent { if (Test-Path "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbam.exe") { return $true } if (Get-Service -Name 'MBAMService' -ErrorAction SilentlyContinue) { return $true } foreach ($p in $ResidualPaths) { if ($p -and (Test-Path $p)) { return $true } } return $false } # --- Main -------------------------------------------------------------------- try { Write-Host "" Write-Host " Nerdy Neighbor - Malwarebytes complete uninstaller" -ForegroundColor Cyan Write-Host "" Write-Log "=== Uninstall run started on $env:COMPUTERNAME (user: $env:USERNAME) ===" if (-not (Test-MalwarebytesPresent)) { Write-Host "" Write-Log "Malwarebytes was not detected on this machine - nothing to remove." 'INFO' Write-Host " Nothing to do - Malwarebytes is not installed." -ForegroundColor Green Write-Host "" exit 0 } try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} # --- Pass 1: normal silent uninstall, survey suppressed ------------------ if (Test-Path $MbunsPath) { Write-Log "Pass 1: running the built-in uninstaller silently (survey suppressed)..." try { $p1 = Start-Process -FilePath $MbunsPath -ArgumentList $MbunsArgs -Wait -PassThru Write-Log "Built-in uninstaller exited with code $($p1.ExitCode)." } catch { Write-Log "Built-in uninstaller failed ($($_.Exception.Message)) - continuing to cleanup pass." 'WARN' } Start-Sleep -Seconds 3 } else { Write-Log "Pass 1: built-in uninstaller not found - going straight to Support Tool cleanup." } # --- Pass 2: official Support Tool cleanup (removes all traces) ---------- Write-Log "Pass 2: downloading the Malwarebytes Support Tool..." $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri $SupportToolUrl -OutFile $Mbst -UseBasicParsing $ProgressPreference = 'Continue' $sizeMB = [math]::Round((Get-Item $Mbst).Length / 1MB, 1) if ($sizeMB -lt 1) { throw "Support Tool download is only $sizeMB MB - looks incomplete." } Write-Log "Downloaded Support Tool ($sizeMB MB). Running cleanup (this can take a few minutes)..." $p2 = Start-Process -FilePath $Mbst -ArgumentList $CleanupArgs -Wait -PassThru Write-Log "Support Tool cleanup exited with code $($p2.ExitCode)." Start-Sleep -Seconds 5 # --- Pass 3: residual folder sweep -------------------------------------- Write-Log "Pass 3: sweeping any residual Malwarebytes folders..." foreach ($p in $ResidualPaths) { if ($p -and (Test-Path $p)) { try { Remove-Item -LiteralPath $p -Recurse -Force -ErrorAction Stop Write-Log "Removed leftover folder: $p" } catch { Write-Log "Could not remove $p ($($_.Exception.Message)) - may need a reboot to release locks." 'WARN' } } } # --- Verify -------------------------------------------------------------- if (Test-MalwarebytesPresent) { Write-Log "Malwarebytes traces still present after cleanup - a reboot then re-run may be required." 'WARN' Write-Host "" Write-Host " Partly removed - some traces remain. Reboot and re-run to finish." -ForegroundColor Yellow Write-Host " Log: $LogFile" -ForegroundColor Gray Write-Host "" exit 1 } Write-Host "" Write-Log "Malwarebytes fully removed - no traces detected." 'INFO' Write-Host " Done. Malwarebytes has been completely removed." -ForegroundColor Green Write-Host "" exit 0 } catch { Write-Log "FAILED: $($_.Exception.Message)" 'ERROR' if ($_.InvocationInfo.ScriptLineNumber) { Write-Log ("At line {0}: {1}" -f $_.InvocationInfo.ScriptLineNumber, $_.InvocationInfo.Line.Trim()) 'ERROR' } Write-Host "" Write-Host " Uninstall failed. Full log: $LogFile" -ForegroundColor Yellow Write-Host "" exit 1 } finally { Remove-Item $Mbst -Force -ErrorAction SilentlyContinue }