#Requires -RunAsAdministrator <# .SYNOPSIS Nerdy Neighbor - Silent installer for the latest Malwarebytes Free (Windows). .NOTES Run with: irm mbam.nerdyneighbor.net | iex (elevated Windows PowerShell) - Downloads the current MBSetup.exe straight from Malwarebytes' evergreen "latest" endpoint, so it is always the newest version. - Installs completely silently (no UI, no prompts, no reboot). - Malwarebytes for Windows is a single product: a fresh install runs a 14-day Premium *trial* and then reverts to Malwarebytes **Free** (the on-demand scanner) automatically. There is no supported command-line switch to skip the trial in the consumer installer, so this script just installs the product on its defaults. - Everything is logged to C:\ProgramData\NerdyNeighbor\mbam-install.log - Exit code 0 = success, 1 = failure. Silent uninstall (for reference): & "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbuns.exe" /VERYSILENT /NORESTART /NOSURVEY #> $ErrorActionPreference = 'Stop' # --- Constants --------------------------------------------------------------- $DownloadUrl = 'https://downloads.malwarebytes.com/file/mb-windows' # evergreen latest $InstallArgs = '/VERYSILENT /NORESTART /SUPPRESSMSGBOXES /NOCANCEL' $LogDir = Join-Path $env:ProgramData 'NerdyNeighbor' $LogFile = Join-Path $LogDir 'mbam-install.log' $Installer = Join-Path $env:TEMP ('MBSetup-{0}.exe' -f (Get-Random)) # --- 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-MalwarebytesInstalled { if (Test-Path "$env:ProgramFiles\Malwarebytes\Anti-Malware\mbam.exe") { return $true } if (Get-Service -Name 'MBAMService' -ErrorAction SilentlyContinue) { return $true } return $false } # --- Main -------------------------------------------------------------------- try { Write-Host "" Write-Host " Nerdy Neighbor - Malwarebytes Free installer" -ForegroundColor Cyan Write-Host "" Write-Log "=== Install run started on $env:COMPUTERNAME (user: $env:USERNAME) ===" if (Test-MalwarebytesInstalled) { Write-Log "Malwarebytes already present - the installer will upgrade it in place." } # Modern TLS for the download on older Windows PowerShell hosts. try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} Write-Log "Downloading the latest Malwarebytes installer..." $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri $DownloadUrl -OutFile $Installer -UseBasicParsing $ProgressPreference = 'Continue' $sizeMB = [math]::Round((Get-Item $Installer).Length / 1MB, 1) if ($sizeMB -lt 1) { throw "Downloaded installer is only $sizeMB MB - download looks incomplete." } Write-Log "Downloaded MBSetup.exe ($sizeMB MB)." Write-Log "Installing silently (this can take a couple of minutes)..." $proc = Start-Process -FilePath $Installer -ArgumentList $InstallArgs -Wait -PassThru Write-Log "Installer exited with code $($proc.ExitCode)." # MBSetup returns 0 on success; some builds return 3010 to signal "reboot required". if ($proc.ExitCode -ne 0 -and $proc.ExitCode -ne 3010) { throw "MBSetup returned a non-success exit code ($($proc.ExitCode))." } # Give the service a moment to register, then verify. Start-Sleep -Seconds 5 if (-not (Test-MalwarebytesInstalled)) { throw "Installer finished but Malwarebytes was not detected on disk/service list." } Write-Host "" Write-Log "Malwarebytes installed successfully." 'INFO' Write-Host " Done. Malwarebytes is installed." -ForegroundColor Green Write-Host " (It runs a 14-day Premium trial, then reverts to Free automatically.)" -ForegroundColor DarkGray 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 " Installation failed. Full log: $LogFile" -ForegroundColor Yellow Write-Host "" exit 1 } finally { Remove-Item $Installer -Force -ErrorAction SilentlyContinue }