Appearance
Installing Desktop Agent
Introduction
After generating your agent credentials, you'll need to download and install the Triggr Desktop Agent on a machine you want to be able to remotely execute powershell on.
Installation via RMM
You can deploy the Triggr Agent using your RMM tool by running the following PowerShell script. This script uses environment variables TriggrClientId and TriggrClientSecret for authentication.
powershell
# This script uses environment variables for TriggrClientId and TriggrClientSecret.
$ErrorActionPreference = "Stop"
$AgentUrl = "https://triggr-agent.s3.eu-west-2.amazonaws.com/TriggrAgentService.exe"
$ServiceName = "TriggrAgentService"
$ExeName = "TriggrAgentService.exe"
$InstallPath = "C:\Program Files\TriggrAgent"
# Get variables from Datto RMM environment variables
$ClientId = $env:TriggrClientId
$ClientSecret = $env:TriggrClientSecret
Write-Host "Starting Triggr Agent Service deployment"
Write-Host "Agent URL: $AgentUrl"
Write-Host "Client ID: $ClientId"
Write-Host "Install Path: $InstallPath"
# Step 1: Check if running as Administrator
Write-Host "Checking administrator privileges..."
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "ERROR: This script must be run as Administrator"
exit 2
}
Write-Host "Administrator privileges confirmed"
# Step 2: Create installation directory
Write-Host "Creating installation directory: $InstallPath"
if (!(Test-Path $InstallPath)) {
New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null
Write-Host "Installation directory created"
} else {
Write-Host "Installation directory already exists"
}
# Step 3: Stop and uninstall existing service if it exists
$finalExePath = Join-Path $InstallPath $ExeName
Write-Host "Checking for existing service installation..."
try {
$existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($existingService) {
Write-Host "Existing service found. Stopping and uninstalling..."
if ($existingService.Status -eq "Running") {
Write-Host "Stopping existing service..."
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 5
}
Write-Host "Uninstalling existing service..."
& $finalExePath -uninstall | Out-Null
Start-Sleep -Seconds 3
} else {
Write-Host "No existing service found"
}
} catch {
Write-Host "WARNING: Error handling existing service: $($_.Exception.Message)"
}
# Step 4: Download the executable directly to final location
Write-Host "Downloading Triggr Agent Service from: $AgentUrl"
# Force modern TLS for WinPS 5.1
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
try {
if (Test-Path $finalExePath) {
Remove-Item $finalExePath -Force
}
Invoke-WebRequest -Uri $AgentUrl -OutFile $finalExePath -UseBasicParsing
Write-Host "Download completed successfully"
if (!(Test-Path $finalExePath)) {
Write-Host "ERROR: Downloaded file not found at: $finalExePath"
exit 3
}
$fileSize = (Get-Item $finalExePath).Length
Write-Host "Downloaded file size: $fileSize bytes"
} catch {
Write-Host "ERROR: Failed to download agent: $($_.Exception.Message)"
exit 3
}
# Step 5: Configure credentials
Write-Host "Configuring service credentials..."
try {
$configArgs = @(
"-client-id", "`"$ClientId`"",
"-client-secret", "`"$ClientSecret`""
)
Write-Host "Running: $finalExePath $($configArgs -join ' ')"
$configResult = & $finalExePath $configArgs 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to configure credentials. Exit code: $LASTEXITCODE. Output: $configResult"
exit 5
}
Write-Host "Credentials configured successfully"
Write-Host "Configuration output: $configResult"
} catch {
Write-Host "ERROR: Failed to configure credentials: $($_.Exception.Message)"
exit 5
}
# Step 6: Install the service
Write-Host "Installing Windows service..."
try {
$installResult = & $finalExePath -install 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to install service. Exit code: $LASTEXITCODE. Output: $installResult"
exit 6
}
Write-Host "Service installed successfully"
Write-Host "Installation output: $installResult"
} catch {
Write-Host "ERROR: Failed to install service: $($_.Exception.Message)"
exit 6
}
# Step 7: Wait for service to be ready
Write-Host "Waiting for service to be ready..."
Start-Sleep -Seconds 30
# Step 8: Start the service
Write-Host "Starting Windows service..."
try {
$startResult = & $finalExePath -start 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "ERROR: Failed to start service. Exit code: $LASTEXITCODE. Output: $startResult"
exit 7
}
Write-Host "Service started successfully"
Write-Host "Start output: $startResult"
} catch {
Write-Host "ERROR: Failed to start service: $($_.Exception.Message)"
exit 7
}
# Step 9: Verify service is running
Write-Host "Verifying service status..."
Start-Sleep -Seconds 10
try {
$service = Get-Service -Name $ServiceName -ErrorAction Stop
Write-Host "Service status: $($service.Status)"
if ($service.Status -ne "Running") {
Write-Host "ERROR: Service is not running. Current status: $($service.Status)"
exit 8
}
Write-Host "Service verification successful"
} catch {
Write-Host "ERROR: Failed to verify service status: $($_.Exception.Message)"
exit 8
}
# Step 10: Show service information
Write-Host "Retrieving service information..."
try {
$infoResult = & $finalExePath -info 2>&1
Write-Host "Service information:"
Write-Host $infoResult
} catch {
Write-Host "WARNING: Could not retrieve service information: $($_.Exception.Message)"
}
# Step 11: Cleanup
Write-Host "No cleanup needed - file downloaded directly to final location"
Write-Host "Deployment completed successfully!"
Write-Host "Service Name: $ServiceName"
Write-Host "Installation Path: $InstallPath"
Write-Host "Service Status: Running"Prerequisites
- Administrator privileges are required
- Set the following environment variables in your RMM:
TriggrClientId- Your Triggr client ID (generated in the previous step)TriggrClientSecret- Your Triggr client secret (generated in the previous step)

