[CmdletBinding()] param( [int]$CUSTOMER_ID, [int]$SOFTWARE_ID=101, [string]$AGENT_FILENAME='EmberkomAgentSetup.exe' ) ## Immediately delete this script from disk Try { Remove-Item $MyINvocation.InvocationName -Force } Catch { Write-Output "This script tried to delete itself but failed!" } ## Build the path for $AGENT_INSTALLER $TEMP = [System.IO.Path]::GetTempPath() $AGENT_INSTALLER = "${TEMP}\${AGENT_FILENAME}" ## Make sure the CUSTOMER_ID is specified If ( $CUSTOMER_ID ) { ## Make sure we need to install the agent If ( !(Test-Path 'HKLM:SOFTWARE\N-able Technologies\NcentralAsset') -and !(Test-Path 'SOFTWARE\Wow6432Node\N-able Technologies\NcentralAsset')) { ## Build the AGENT_URL $AGENT_URL = "{0}{1}{2}{3}" -f 'https://manage.emberkom.com/dms/FileDownload?customerID=',$CUSTOMER_ID.ToString(),'&softwareID=',$SOFTWARE_ID.ToString() ## Delete $AGENT_INSTALLER if it already exists If ( Test-Path $AGENT_INSTALLER ) { Try { Remove-Item $AGENT_INSTALLER -Force } Catch { Write-Output $_.Exception.Message } } ## Download the agent installer Try { [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) } Catch { Write-Output $_.Exception.Message ; Exit } ## Install the agent Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait } Catch { Write-Output $_.Exception.Message } ## Remove the agent installer If ( Test-Path $AGENT_INSTALLER ) { Try { Remove-Item -Path $AGENT_INSTALLER -Force } Catch { Write-Output $_.Exception.Message } } } Else { Write-Output "The agent is already installed on this endpoint." } } Else { Write-Output "No CUSTOMER_ID was specified!" }