param(
    [Parameter(Mandatory=$true)][string]$TOKEN,
    [Parameter(Mandatory=$true)][int]$CUSTOMER_ID,
    [Parameter(Mandatory=$false)][int]$SOFTWARE_ID=101,
    [Parameter(Mandatory=$false)][string]$SERVER='manage.emberkom.com',
    [Parameter(Mandatory=$false)][string]$AGENT_FILENAME='EmberkomAgentSetup.exe'
)

## Source the Tools.ps1 script
Function SourceTools
{ . $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) }
. SourceTools

## Build the path for $AGENT_INSTALLER
$AGENT_INSTALLER = '{0}{1}' -f (GetTempPath), $AGENT_FILENAME

## Get the right path to agent.exe based on the system bit-level
If ( Is64bit ) { $AGENT_EXE = "${Env:ProgramFiles(x86)}\N-able Technologies\Windows Agent\bin\agent.exe" }
Else           { $AGENT_EXE = "${Env:ProgramFiles}\N-able Technologies\Windows Agent\bin\agent.exe" }

## Make sure we need to install the agent
If ( !(Test-Path $AGENT_EXE) )
{
    ## Download agent and get path
    $AGENT_INSTALLER = Download-File -URL 'https://manage.emberkom.com/download/2020.1.5.425/winnt/N-central/WindowsAgentSetup.exe' -File $AGENT_INSTALLER

    ## Install the agent
    Install-Program $AGENT_INSTALLER -Arguments "/s /v"" /qn CUSTOMERID=${CUSTOMER_ID} CUSTOMERSPECIFIC=1 REGISTRATION_TOKEN=${TOKEN} SERVERPROTOCOL=HTTPS SERVERADDRESS=${SERVER} SERVERPORT=443""" -Delete

} Else { LogMsg "N-Central agent is already installed on this endpoint." }

