Liongard Agent Silent Installation Using LGAgentScript.ps1
This guide contains everything required to deploy the Liongard Agent in a silent, automated, and duplicate-safe manner using the LGAgentScript PowerShell script.
You can download the script by clicking the following link. Just be sure to input your variables and rename it to"LGAgentScript.ps1" before use:
This script supports:
Mass RMM deployment
Optional uninstall + cleanup prior to reinstall
Machine identity collision prevention
Safe backend record deletion (optional)
π§ What LGAgentScript.ps1 Does
Functionality | Description |
Silent installation | MSI deployment without prompts |
Validates configuration inputs | Prevents empty or placeholder values |
Detects MachineGuid collisions | Prevents agent overwrite scenarios |
Generates override DEVICEGUID | Only when a collision is confirmed |
Optional uninstall prior to install | Removes service, folder, registry keys |
Optional deletion of backend record | Only when the scoring threshold is met |
Transcript logging | Creates a full script execution trace |
Installer logging | Captures MSI installer result |
β Script Configuration in LGAgentScript.ps1
Update this section at the top of the file or map via RMM variables:
$InstancePrefix = 'us?'
$ApiTokenKey = 'YOUR_API_TOKEN_KEY'
$ApiTokenSecret = 'YOUR_API_TOKEN_SECRET'
$AgentTokenKey = 'YOUR_AGENT_INSTALL_KEY'
$AgentTokenSecret = 'YOUR_AGENT_INSTALL_SECRET'
$Environment = 'ENVIRONMENT NAME'
$EnablePreUninstall = $true
$IncludeEnvironmentValue = $true
$RemoveAgentFromPlatform = $false
$MinimumRemoteDeletionScore = 50
π RMM Deployment Instructions
When executed without an interactive session, LGAgentScript.ps1 enters Headless Mode and reads variables from its configuration or from environment variables passed by your RMM.
1οΈβ£ Datto RMM
β‘ Automation β Components β New Component
Field | Value |
Category | Script β PowerShell |
Script | Paste |
β‘ Variables to Map
Datto Variable | Script Variable |
InstancePrefix |
|
ApiTokenKey |
|
ApiTokenSecret |
|
AgentTokenKey |
|
AgentTokenSecret |
|
Environment |
|
β‘ Execution
powershell.exe -ExecutionPolicy Bypass -File "LGAgentScript.ps1"
2οΈβ£ ConnectWise Automate (CWA)
β‘ Add Script β Insert "Execute Script β PowerShell"
β‘ Parameter section example:
Set-Variable InstancePrefix "us?"
Set-Variable ApiTokenKey "YOUR_API_KEY"
Set-Variable ApiTokenSecret "YOUR_API_SECRET"
Set-Variable AgentTokenKey "YOUR_AGENT_KEY"
Set-Variable AgentTokenSecret "YOUR_AGENT_SECRET"
Set-Variable Environment "%ClientName%"
β %ClientName% auto-inserts the environment name.
3οΈβ£ NinjaOne
β‘ Configuration β Scripting β Add Script
β‘ Parameters Example:
InstancePrefix = us?
ApiTokenKey = YOUR_KEY
ApiTokenSecret = YOUR_SECRET
AgentTokenKey = YOUR_AGENT_KEY
AgentTokenSecret = YOUR_AGENT_SECRET
Environment = $msg.organization_name
4οΈβ£ Kaseya VSA
β‘ Upload script to:
#vAgentConfiguration.agentTempDir#\LGAgentScript.ps1
β‘ Execute:
powershell.exe -ExecutionPolicy Bypass -File "#vAgentConfiguration.agentTempDir#\LGAgentScript.ps1"
π§― Troubleshooting & Logs
LGAgentScript.ps1 generates two log files every run.
Log | Description | Location |
Script Transcript & Diagnostic Log | Machine identity decisions, uninstall logic, deletion scoring, environment processing |
|
MSI Installer Log | MSI exit code, errors, silent failure reasoning |
|
If Deployment Fails
π Check RMM Output
The script returns readable console messages.
π Check the MSI Log:
Path β C:\Liongard\AgentInstall.log
Useful for:
1603 Fatal error
Blocked by security tool
Incorrect MSI parameters
Missing permissions
π Check the Script Transcript Log:
Path β C:\Liongard\LGAgentScript_<timestamp>.log
Shows:
Matched identities and scoring
Whether DEVICEGUID override was required
Whether removal was allowed
Why backend deletion was skipped
π Script Outline
When running, the script:
1οΈβ£ Validates configuration values
2οΈβ£ Optionally uninstalls any existing Liongard Agent
3οΈβ£ Detects MachineGuid conflicts with existing agents
4οΈβ£ Generates a DEVICEGUID override if necessary
5οΈβ£ Calls MSI installer silently
6οΈβ£ Evaluates MSI success & logs outcomes
7οΈβ£ Records execution details in transcript log
8οΈβ£ Exits with a clean success or failure code for RMM interpretation
β Disclaimer
Liongard provides this script as-is and is not responsible for custom modifications or misuse. Always validate configuration values and test in a controlled environment prior to mass deployment to avoid unintended disruptions.