# HomeRMM agent installer for Windows # Usage: irm https://homermm.mk03.uk/install/agent.ps1 | iex # The enrollment token is optional — without one, the agent waits for approval in the console. $ErrorActionPreference = 'Stop' $Server = 'https://homermm.mk03.uk' $Token = '' if ($env:HOMERMM_TOKEN) { $Token = $env:HOMERMM_TOKEN } elseif ($env:HOMMR_TOKEN) { $Token = $env:HOMMR_TOKEN } $Root = Join-Path $env:ProgramData 'HomeRMM\agent' New-Item -ItemType Directory -Force -Path $Root | Out-Null $Zip = Join-Path $Root 'agent.zip' Write-Host "Downloading agent from $Server ..." [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 try { Invoke-WebRequest -Uri "$Server/install/agent.zip" -OutFile $Zip -UseBasicParsing } catch { Invoke-WebRequest -Uri "$Server/install/agent.zip" -OutFile $Zip -UseBasicParsing -SkipCertificateCheck } Expand-Archive -Path $Zip -DestinationPath $Root -Force $Node = Get-Command node -ErrorAction SilentlyContinue $Npm = Get-Command npm -ErrorAction SilentlyContinue $NodeExe = $null $NpmCmd = $null if ($Node) { $NodeExe = $Node.Source } if ($Npm) { $NpmCmd = $Npm.Source } if (-not $NodeExe) { Write-Host 'Node.js not found on PATH. Downloading portable Node.js ...' $NodeVer = 'v20.18.1' $NodeZip = Join-Path $Root 'node.zip' $NodeUrl = "https://nodejs.org/dist/$NodeVer/node-$NodeVer-win-x64.zip" Invoke-WebRequest -Uri $NodeUrl -OutFile $NodeZip -UseBasicParsing Expand-Archive -Path $NodeZip -DestinationPath $Root -Force $NodeDir = Join-Path $Root "node-$NodeVer-win-x64" $NodeExe = Join-Path $NodeDir 'node.exe' $NpmCmd = Join-Path $NodeDir 'npm.cmd' } Write-Host 'Installing agent libraries ...' Push-Location $Root try { if ($NpmCmd) { & $NpmCmd install --omit=dev } } finally { Pop-Location } $Config = @{ server = 'auto' fallback = 'https://homermm.mk03.uk' token = $Token name = $env:COMPUTERNAME } | ConvertTo-Json Set-Content -Path (Join-Path $Root 'agent.json') -Value $Config -Encoding UTF8 $Action = New-ScheduledTaskAction -Execute $NodeExe -Argument 'index.js' -WorkingDirectory $Root $Trigger = New-ScheduledTaskTrigger -AtLogOn $Principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Highest try { Unregister-ScheduledTask -TaskName 'HomeRMM Agent' -Confirm:$false -ErrorAction SilentlyContinue Unregister-ScheduledTask -TaskName 'HomerMM Agent' -Confirm:$false -ErrorAction SilentlyContinue } catch {} Register-ScheduledTask -TaskName 'HomeRMM Agent' -Action $Action -Trigger $Trigger -Principal $Principal -Force | Out-Null Start-ScheduledTask -TaskName 'HomeRMM Agent' Write-Host "HomeRMM agent installed in $Root and started." Write-Host 'Remote desktop works best when the agent runs in the logged-in user session (this installer does that).'