What It Does
This script changes nothing until you set DryRun=false and Approve=uninstall-rmm-agent. The dry run lists every step and fails when the product has no known silent uninstall method. It refuses to make more than 25 changes in one run unless you raise MaxChanges.
It removes one named RMM or remote-management agent, picked from the same list get-rmm-agents reports. There is no all: one product per run. In order, it runs the product's silent uninstaller from the installed-programs list, stops and deletes the product's leftover Windows services, removes its leftover scheduled tasks, and deletes its program folders, stopping any process still running from them. An entry whose uninstaller file is already gone is removed as a stale entry. Before it removes a service, a stale entry or a scheduled task it backs up that registry key or the task under the MSPOutpost backup folder.
It never touches a product other than the one named, Microsoft Intune or ScreenConnect, which has remove-screenconnect-instances. It normally refuses to remove the product whose agent is running this script. If the product's service or program folder belongs to the script's own process chain, the run stops with an error unless Force is true, and then the script is probably cut off half way.
For a tamper-protected NinjaOne agent, put its removal key in the environment variable RemovalKey, in a secret or hidden field in your RMM. The script takes no key argument and does not print the key. It warns and ignores this input for the other agents. For NinjaOne the key goes on the msiexec command line, so if you audit process creation with command lines it is recorded. Use a removal key you can rotate afterwards.
Before You Run It
- Make sure the new RMM agent is installed and checking in before you remove the old one. This script cannot undo an uninstall.
- Run it once as a dry run and read every step.
- For a tamper-protected NinjaOne agent, set the RemovalKey environment variable in a secret field. Rotate the key afterwards if command lines are logged.
- Do not run it from the agent you are removing unless you accept Force and a half finished run.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: High. It is a dry run unless you set both DryRun=false and Approve=uninstall-rmm-agent, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
- What it changes: Runs the agent's silent uninstaller, deletes its leftover services, scheduled tasks and program folders.
- Restart: It never restarts the machine itself. When a restart is needed to finish, the answer says so.
- Typical run: 1 to 10 minutes.
- Example answer: "Removed Datto RMM (1 uninstaller, 1 service, 0 tasks, 2 folders)"
- Tested before listing on Windows 11 with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- Product: The agent to remove, as get-rmm-agents names it, for example "Datto RMM" or NinjaOne. Spaces, case and punctuation do not matter (DattoRMM works). Required.
- Force: true to remove the product even when it is the agent running this script. Default false.
- TimeoutSeconds: How long to wait for the uninstaller. Whole number, 30 to 7200. Default 600.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.