This guide contains everything required to remove the Liongard Agent in a silent, automated, and cleanup-safe manner using the LGAgentUninstall PowerShell script.
Use this script when you need to:
Remove the local Liongard Agent (service/process/files/registry remnants)
Address “stuck” or corrupted installer artifacts that prevent reinstall/upgrade
Optionally remove the matching Agent record from the Liongard platform (API delete) when you’re confident you’ve identified the correct record
Click the following link to download the script. Be sure to rename it to a .ps1 before use:
Scripts are named LGAgentUninstall_YYYYMMDD to indicate the build date; YYYYMMDD reflects when the script was generated so partners can confirm they’re using the latest version.
What LGAgentUninstall.ps1 Does
Functionality | Description |
Silent uninstall | Attempts uninstall via registry uninstall strings and MSI product code (quiet + no restart) |
Duplicate-safe detection | Checks common Liongard service names and known MSI uninstall registry keys to detect presence |
Registry cleanup | Removes uninstall keys it finds and cleans hidden Windows Installer cache entries that can cause MSI errors |
Service cleanup | Stops and deletes common Liongard Agent service name variants |
Process cleanup | Terminates common Liongard Agent process names |
Folder cleanup | Removes |
Transcript logging | Saves a full execution trace to a timestamped log file |
Optional platform record deletion | Can delete the matching Liongard Agent record via API if confidence scoring meets the threshold |
⚙ Script Configuration in LGAgentUninstall.ps1
Update this section at the top of the file (or map via your RMM variables):
Required (always)
Variable | Description | Example |
| Where the transcript log is written |
|
Optional (only if you want platform deletion)
These are required only if $RemoveAgentFromPlatform = $true
Variable | Description | Example |
| Your Liongard region/instance prefix |
|
| Liongard API Token Key | (provided by Liongard UI) |
| Liongard API Token Secret | (provided by Liongard UI) |
| Enables remote deletion of the agent record |
|
| Confidence threshold for remote deletion |
|
Best practice: Keep $RemoveAgentFromPlatform = $false unless you explicitly need to remove the backend Agent record (for example, after cloning/templating incidents, stale record cleanup, or redeployments where the backend record must be reset).
Prerequisites
Before running the script, ensure:
The endpoint is running Windows and has PowerShell 5.1+
The script is executed as SYSTEM or Administrator
If using remote deletion:
The endpoint has outbound HTTPS (TCP 443) access to your Liongard instance
You have a valid API Token Key/Secret for the instance
Script Outline
When running the script:
Enables TLS 1.2 for web requests
Starts transcript logging to the configured
$LogFolderAttempts to uninstall Liongard Agent using:
Registry uninstall entries (quiet uninstall when available)
Known MSI product code uninstall as a fallback
Cleans hidden Windows Installer cache entries related to Liongard (helps resolve MSI “ghost” entries)
Stops/deletes common Liongard services
Terminates any remaining Liongard processes
Removes the residual Liongard program folder (with permission reset if required)
Validates whether the agent is still detected locally
(Optional) Deletes the matching Liongard Agent record from the platform only if:
Local agent is no longer detected, and
Uninstall did not report blocking issues, and
A matching backend agent is found with a confidence score ≥
$MinimumRemoteDeletionScore
Stops transcript logging and exits with a success/failure code suitable for RMM interpretation
Remote Agent Record Deletion (Optional)
If $RemoveAgentFromPlatform = $true, the script will attempt to identify the correct Liongard Agent record and delete it via the Liongard API.
How matching works (confidence scoring)
The script builds a local identity profile using:
Hostname variants (Hostname/NETBIOS/DNS/FQDN)
MAC address matches (from enabled NICs)
It then scores candidate agent records and will skip deletion unless the score meets the minimum threshold (default: 50).
Safety behavior
Remote deletion is automatically skipped if:
The agent is still detected locally after uninstall
Uninstall reported blocking issues (non-folder issues)
No agent record is returned by the filtered lookup
Match score is below the minimum threshold
Troubleshooting & Logs
LGAgentUninstall.ps1 generates a transcript log for each run.
Log | Description | Location |
Script Transcript Log | Full uninstall trace, service/process removal, folder cleanup, and (optional) remote deletion decisions |
|
If uninstall fails or the agent still appears installed
Check the transcript log for:
MSI exit codes returned by
msiexecAny services that could not be deleted
Folder deletion failures (and whether permission reset was attempted)
Whether remote deletion was skipped, and why
Exit Codes
0 = Agent not detected after uninstall (success)
1 = Agent still detected after uninstall attempt (failure)
⚠ Disclaimer
Liongard provides this script as-is and is not responsible for custom modifications or misuse. Always validate your configuration values and test in a controlled environment prior to mass execution to avoid unintended disruptions—especially when enabling platform record deletion.