49 lines
2.0 KiB
PowerShell
49 lines
2.0 KiB
PowerShell
[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 "The agent installer already exists but there was an error when trying to delete it!" }
|
|
}
|
|
|
|
## Download the agent installer
|
|
Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) }
|
|
Catch { Write-Output "There was an error downloading the agent installer!"; Exit }
|
|
|
|
## Install the agent
|
|
Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait }
|
|
Catch { Write-Output "There was an error installing the agent!" }
|
|
New-Item -Path $Env:SYSTEMDRIVE -Name "ready-for-install" -ItemType "file" -Value ""
|
|
|
|
## Remove the agent installer
|
|
If ( Test-Path $AGENT_INSTALLER )
|
|
{
|
|
Try { Remove-Item -Path $AGENT_INSTALLER -Force }
|
|
Catch { Write-Output "There was an error while deleting the agent installer!" }
|
|
}
|
|
} Else { Write-Output "The agent is already installed on this endpoint." }
|
|
} Else { Write-Output "No CUSTOMER_ID was specified!" }
|