# GuruRMM Agent Uninstaller # Compatible with: Windows 7 SP1+ / PowerShell 2.0+ $ErrorActionPreference = "Stop" $InstallPath = "C:\Program Files\GuruRMM" $ConfigPath = "C:\ProgramData\GuruRMM" $ServiceName = "GuruRMMAgent" Write-Host "GuruRMM Agent Uninstaller" -ForegroundColor Cyan Write-Host "==========================" -ForegroundColor Cyan Write-Host "" # Check for admin privileges $isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator") if (-not $isAdmin) { Write-Host "ERROR: Please run as Administrator" -ForegroundColor Red Write-Host "Right-click PowerShell and select 'Run as Administrator'" exit 1 } # Check if agent executable exists $agentExe = "$InstallPath\gururmm-agent.exe" if (Test-Path $agentExe) { # Use the agent's built-in uninstall command Write-Host "Running agent uninstall..." -ForegroundColor Yellow $uninstallResult = & $agentExe uninstall 2>&1 Write-Host $uninstallResult Start-Sleep -Seconds 3 } else { # Manual cleanup if agent exe is missing Write-Host "Agent executable not found, performing manual cleanup..." -ForegroundColor Yellow # Try to stop and remove service manually $service = $null try { $service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue } catch {} if ($service) { Write-Host "Stopping service..." -ForegroundColor Yellow try { Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue } catch {} Start-Sleep -Seconds 2 Write-Host "Removing service..." -ForegroundColor Yellow $scResult = & sc.exe delete $ServiceName 2>&1 Write-Host $scResult Start-Sleep -Seconds 2 } } # Remove install directory if (Test-Path $InstallPath) { Write-Host "Removing install directory: $InstallPath" -ForegroundColor Yellow try { Remove-Item -Path $InstallPath -Recurse -Force -ErrorAction Stop Write-Host " Removed successfully" -ForegroundColor Gray } catch { Write-Host " WARNING: Could not remove (files may be in use)" -ForegroundColor Yellow Write-Host " Try again after reboot or manually delete: $InstallPath" } } # Ask about config directory if (Test-Path $ConfigPath) { Write-Host "" Write-Host "Config directory exists: $ConfigPath" -ForegroundColor Yellow Write-Host "This contains your agent configuration (agent.toml)." Write-Host "" $response = Read-Host "Remove config directory? (y/N)" if ($response -eq "y" -or $response -eq "Y") { try { Remove-Item -Path $ConfigPath -Recurse -Force -ErrorAction Stop Write-Host "Config directory removed" -ForegroundColor Gray } catch { Write-Host "WARNING: Could not remove config directory" -ForegroundColor Yellow } } else { Write-Host "Config directory preserved at: $ConfigPath" -ForegroundColor Gray } } Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host "GuruRMM Agent uninstalled successfully!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green