Files
management-scripts/Remove-NinjaRMMAgent.ps1
2019-11-11 19:22:39 -05:00

29 lines
1.3 KiB
PowerShell

## Get the NinjaRMM installation directory
If (Test-Path "${Env:ProgramFiles(x86)}") {
$INSTALLDIR = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\WOW6432Node\NinjaRMM LLC\NinjaRMMAgent').Location
} Else {
$INSTALLDIR = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\NinjaRMM LLC\NinjaRMMAgent').Location
}
## Stop the Ninja processes and service
Stop-Process -Name NinjaRMMAgent
Stop-Process -Name NinjaRMMAgentPatcher
## Run Ninja's uninstaller
If ( Test-Path "${INSTALLDIR}\uninstall.exe") {
Start-Process -FilePath "${INSTALLDIR}\uninstall.exe" -ArgumentList "--mode unattended" -Wait
}
## Clean up remaining service registry entries
Start-Process -FilePath "sc.exe" -ArgumentList "delete NinjaRMMAgent"
## Clean up remaining directories
If (Test-Path "${INSTALLDIR}") { Remove-Item -Path "${INSTALLDIR}" -Recurse -Force }
If (Test-Path "${Env:ProgramData}\NinjaRMMAgent") { Remove-Item -Path "${Env:ProgramData}\NinjaRMMAgent" -Recurse -Force }
## Clean up remaining registry entries
If ( Test-Path $(Split-Path -Path $WOW64RegKey -Parent) ) { Remove-Item -Path $(Split-Path -Path $WOW64RegKey -Parent) -Recurse -Force }
If ( Test-Path $(Split-Path -Path $RegKey -Parent) ) { Remove-Item -Path $(Split-Path -Path $RegKey -Parent) -Recurse -Force }
## Remove the NinjaRMMAgent service
Start-Process "sc.exe" -ArgumentList "delete NinjaRMMAgent" -Wait