2020-05-22 14:35:46 -04:00
|
|
|
[CmdletBinding()]
|
|
|
|
|
param(
|
2020-05-22 16:09:14 -04:00
|
|
|
[int]$CUSTOMER_ID,
|
|
|
|
|
[int]$SOFTWARE_ID=101,
|
2020-05-22 14:35:46 -04:00
|
|
|
[string]$AGENT_FILENAME='EmberkomAgentSetup.exe'
|
|
|
|
|
)
|
|
|
|
|
|
2020-06-22 10:57:58 -04:00
|
|
|
## Setup log file and function to write to it
|
2020-06-22 11:49:35 -04:00
|
|
|
$LOGFILE = "{0}EmberkomAgentSetup_{1}.log" -f "${Env:WINDIR}\Temp", $(Get-Date -Format "yyyyMMddHHmmss")
|
2020-06-22 10:57:58 -04:00
|
|
|
If (! (Test-Path $LOGFILE) ) { New-Item -Path $LOGFILE -ItemType File }
|
|
|
|
|
Function Write-Log([string]$message)
|
|
|
|
|
{
|
|
|
|
|
$entry = "{0} : {1}" -f $(Get-Date -Format "yyyyMMddHHmmss"), $Message
|
|
|
|
|
Add-Content -Path $LOGFILE -Value $entry
|
|
|
|
|
}
|
|
|
|
|
Write-Log "Agent installation script has started"
|
|
|
|
|
|
2020-05-22 16:09:14 -04:00
|
|
|
## Immediately delete this script from disk
|
2020-06-22 10:57:58 -04:00
|
|
|
$THIS_SCRIPT = $MyInvocation.InvocationName
|
|
|
|
|
Write-Log "Deleting this script: ${THIS_SCRIPT}"
|
|
|
|
|
Try { Remove-Item $MyInvocation.InvocationName -Force }
|
|
|
|
|
Catch { Write-Log "This script tried to delete itself but failed!" }
|
|
|
|
|
|
|
|
|
|
Write-Log "CUSTOMER_ID: ${CUSTOMER_ID}"
|
|
|
|
|
Write-Log "SOFTWARE_ID: ${SOFTWARE_ID}"
|
2020-05-22 16:09:14 -04:00
|
|
|
|
2020-06-22 11:49:35 -04:00
|
|
|
## Build the path for $AGENT_INSTALLER
|
|
|
|
|
$TEMP = [System.IO.Path]::GetTempPath()
|
2020-05-22 14:35:46 -04:00
|
|
|
$AGENT_INSTALLER = "${TEMP}\${AGENT_FILENAME}"
|
2020-06-22 10:57:58 -04:00
|
|
|
Write-Log "Agent installer will be saved to: ${AGENT_INSTALLER}"
|
2020-05-22 14:35:46 -04:00
|
|
|
|
2020-05-22 16:09:14 -04:00
|
|
|
## Make sure the CUSTOMER_ID is specified
|
|
|
|
|
If ( $CUSTOMER_ID )
|
2020-05-22 14:35:46 -04:00
|
|
|
{
|
|
|
|
|
## 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'))
|
|
|
|
|
{
|
2020-05-22 16:09:14 -04:00
|
|
|
## 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 )
|
|
|
|
|
{
|
2020-06-22 10:57:58 -04:00
|
|
|
Write-Log "Deleting previous agent installer: ${AGENT_INSTALLER}"
|
2020-05-22 16:09:14 -04:00
|
|
|
Try { Remove-Item $AGENT_INSTALLER -Force }
|
2020-06-22 10:57:58 -04:00
|
|
|
Catch { Write-Log $_.Exception.Message }
|
2020-05-22 16:09:14 -04:00
|
|
|
}
|
|
|
|
|
|
2020-06-22 10:57:58 -04:00
|
|
|
### Setup security and certificate parameters to download from untrusted sources
|
|
|
|
|
#[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
|
|
|
|
|
#[Net.ServicePointManager]::SecurityProtocol =
|
|
|
|
|
# [Net.SecurityProtocolType]::Tls12 -bor `
|
|
|
|
|
# [Net.SecurityProtocolType]::Tls11 -bor `
|
|
|
|
|
# [Net.SecurityProtocolType]::Tls
|
2020-05-24 15:28:49 -04:00
|
|
|
|
|
|
|
|
## Download the agent installer
|
2020-06-22 10:57:58 -04:00
|
|
|
Write-Log "Downloading agent installer from: ${AGENT_URL}"
|
2020-05-24 15:23:48 -04:00
|
|
|
Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) }
|
2020-06-22 10:57:58 -04:00
|
|
|
Catch { Write-Log $_.Exception.Message ; Exit }
|
2020-05-22 14:35:46 -04:00
|
|
|
|
|
|
|
|
## Install the agent
|
2020-06-22 10:57:58 -04:00
|
|
|
Write-Log "Begin installing agent"
|
2020-05-22 16:09:14 -04:00
|
|
|
Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait }
|
2020-06-22 10:57:58 -04:00
|
|
|
Catch { Write-Log $_.Exception.Message }
|
2020-05-22 16:09:14 -04:00
|
|
|
|
|
|
|
|
## Remove the agent installer
|
|
|
|
|
If ( Test-Path $AGENT_INSTALLER )
|
|
|
|
|
{
|
2020-06-22 10:57:58 -04:00
|
|
|
Write-Log "Deleting agent installer: ${AGENT_INSTALLER}"
|
2020-05-22 16:09:14 -04:00
|
|
|
Try { Remove-Item -Path $AGENT_INSTALLER -Force }
|
2020-06-22 10:57:58 -04:00
|
|
|
Catch { Write-Log $_.Exception.Message }
|
2020-05-22 16:09:14 -04:00
|
|
|
}
|
2020-06-22 10:57:58 -04:00
|
|
|
|
|
|
|
|
Write-Log "Agent installation script has finished"
|
|
|
|
|
} Else { Write-Log "The agent is already installed on this endpoint." }
|
|
|
|
|
} Else { Write-Log "No CUSTOMER_ID was specified!" }
|