Skip to content
Menu

Remove ScreenConnect Instances That Are Not Yours

Finds every ScreenConnect client instance on the PC, keeps the ids in AllowedInstanceIds and removes the rest. Needs DryRun=false and Approve=remove-screenconnect-instances.

Remove ScreenConnect instances that are not yours is free for members.

Enter your email to create your free account and get the file.

We'll email you the script and the weekly MSP Outpost email. Unsubscribe anytime. Privacy policy.

Already a member? Sign in.

Be the first to review Remove ScreenConnect instances that are not yours. Tell other MSPs how it worked for you.

Write a Review

LanguagePowerShell
Runs onWindows 10, Windows 11, Windows Server 2016+; runs as SYSTEM
NeedsPowerShell 5.1, administrator rights
Changes thingsChanges what it runs on

What It Does

This script changes nothing until you set DryRun=false and Approve=remove-screenconnect-instances. The dry run lists every instance and what would be removed. It refuses to make more than 25 changes in one run unless you raise MaxChanges.

Every ScreenConnect server an agent was ever installed from leaves its own ScreenConnect Client service, installed program and folder on the PC. The script finds every instance, keeps the ones whose id is in AllowedInstanceIds, which are your servers, and removes the others. For each one it uninstalls through the Windows Installer product code with msiexec /x, stops and deletes the Windows service if the uninstall left it, and deletes the program folder if the uninstall left it. Before it deletes a service it backs up the service's registry key with reg export.

AllowedInstanceIds is required unless you set RemoveAll to true. With RemoveAll, the list must be empty. If a removable instance is the agent running this script, the run stops before changing anything and tells you to add it to AllowedInstanceIds. If any target is marked NoRemove or has an installed-programs entry without a Windows Installer product code, the run refuses before uninstalling anything. Exit codes 3010 and 1641 from an uninstaller count as success and mean a reboot is needed, which the answer says and the script never does.

It is for Windows only. Find the instance ids first with get-remote-access-tools, where the Evidence column says Instance and the id, or in your ScreenConnect server, where the service name ends with the id in brackets.

Before You Run It

  • Find your own instance id first, and put it in AllowedInstanceIds. Otherwise you remove your own access.
  • Run it once as a dry run and read every instance it would remove.
  • Know that macOS and Linux ScreenConnect clients are not handled.
  • Plan for a reboot to finish if an uninstaller reports one. The script never restarts the PC.

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=remove-screenconnect-instances, 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: Uninstalls ScreenConnect client instances not on the allow-list and deletes their leftover services and folders.
  • Restart: It never restarts the machine itself. When a restart is needed to finish, the answer says so.
  • Typical run: 1 to 5 minutes.
  • Example answer: "Removed 2 ScreenConnect instances: 1a2b3c4d5e6f7a8b, 9f8e7d6c5b4a3f2e; kept 1: 0123456789abcdef; reboot needed"
  • 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.

  • AllowedInstanceIds: Instance ids to KEEP, separated by commas, semicolons or new lines, for example 0123456789abcdef. The full service name "ScreenConnect Client (0123456789abcdef)" is accepted too. Required unless RemoveAll is true.
  • RemoveAll: true to remove every ScreenConnect instance, with an empty AllowedInstanceIds. Default false.
  • TimeoutSeconds: How long to wait for each 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.

The Script

remove-screenconnect-instances.ps1 · 1184 lines · 60.7 KB

Free for Members

Create a free account or sign in to read, copy and download this script.

Welcome Back

Sign in to your MSP Outpost account.