Files
management-scripts/Install-ManagementAgent.ps1
T

55 lines
2.2 KiB
PowerShell
Raw Normal View History

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-05-22 16:09:14 -04:00
## 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
2020-05-22 14:35:46 -04:00
$TEMP = [System.IO.Path]::GetTempPath()
$AGENT_INSTALLER = "${TEMP}\${AGENT_FILENAME}"
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 )
{
Try { Remove-Item $AGENT_INSTALLER -Force }
2020-05-24 15:20:28 -04:00
Catch { Write-Output $_.Exception.Message }
2020-05-22 16:09:14 -04:00
}
2020-05-24 15:28:49 -04:00
## Setup security and certificate parameters to download from untrusted sources
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
2020-05-28 08:43:51 -04:00
[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
Try { (New-Object System.Net.WebClient).DownloadFile($AGENT_URL, $AGENT_INSTALLER) }
2020-05-24 15:20:28 -04:00
Catch { Write-Output $_.Exception.Message ; Exit }
2020-05-22 14:35:46 -04:00
## Install the agent
2020-05-22 16:09:14 -04:00
Try { Start-Process $AGENT_INSTALLER -ArgumentList '/quiet /passive' -Wait }
2020-05-24 15:20:28 -04:00
Catch { Write-Output $_.Exception.Message }
2020-05-22 16:09:14 -04:00
## Remove the agent installer
If ( Test-Path $AGENT_INSTALLER )
{
Try { Remove-Item -Path $AGENT_INSTALLER -Force }
2020-05-24 15:20:28 -04:00
Catch { Write-Output $_.Exception.Message }
2020-05-22 16:09:14 -04:00
}
} Else { Write-Output "The agent is already installed on this endpoint." }
} Else { Write-Output "No CUSTOMER_ID was specified!" }