2021-01-21 12:32:59 -05:00
|
|
|
param(
|
2022-04-16 09:49:58 -04:00
|
|
|
[Parameter(Mandatory=$false)][int]$CUSTOMER_ID=1,
|
2022-04-16 10:25:53 -04:00
|
|
|
[Parameter(Mandatory=$false)][string]$INTEGRATOR_ID,
|
2021-08-11 16:05:03 -04:00
|
|
|
[Parameter(Mandatory=$false)][string]$AGENT_FILENAME="AteraAgentSetup.msi",
|
2021-02-03 09:58:32 -05:00
|
|
|
[Parameter(Mandatory=$false)][switch]$FORCE
|
2021-01-21 12:32:59 -05:00
|
|
|
)
|
|
|
|
|
|
2022-04-16 10:25:53 -04:00
|
|
|
# Make sure $INTEGRATOR_ID exists, otherwise exit this script as an agent cannot be downloaded
|
2022-04-16 10:33:54 -04:00
|
|
|
#If ( ($INTEGRATOR_ID -eq $null) -or ($INTEGRATOR_ID -eq '') ) { Exit }
|
2022-04-16 10:25:53 -04:00
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Source the Tools.ps1 script
|
2021-01-21 12:32:59 -05:00
|
|
|
Function SourceTools
|
|
|
|
|
{ . $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString('https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1'))) }
|
|
|
|
|
. SourceTools
|
|
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Build the path for $AGENT_INSTALLER
|
2021-02-08 16:54:08 -05:00
|
|
|
$AGENT_INSTALLER = '{0}{1}' -f (GetTempPath), $AGENT_FILENAME
|
2021-01-21 12:32:59 -05:00
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Make sure we need to install the agent
|
2021-02-08 16:36:42 -05:00
|
|
|
If ( (Test-Path "${Env:ProgramFiles}\ATERA Networks\AteraAgent\AteraAgent.exe") -or (Test-Path "${Env:ProgramFiles(x86)}\ATERA Networks\AteraAgent\AteraAgent.exe") )
|
2022-04-16 11:00:30 -04:00
|
|
|
{ $INSTALL = $false ; $PreviousInstall = $true ; LogMsg "Atera agent is already installed on this endpoint" } Else { $INSTALL = $true ; $PreviousInstall = $false }
|
2021-02-08 16:36:42 -05:00
|
|
|
|
2021-01-27 11:35:21 -05:00
|
|
|
If ( $FORCE ) { $INSTALL = $true }
|
2021-02-08 16:36:42 -05:00
|
|
|
|
2021-01-27 11:35:21 -05:00
|
|
|
If ( $INSTALL ) {
|
2021-01-21 12:32:59 -05:00
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Uninstall if $FORCE is true
|
2021-02-08 16:36:42 -05:00
|
|
|
If ( $PreviousInstall ) {
|
2022-04-15 13:26:29 -04:00
|
|
|
LogMsg "Getting information from existing installation"
|
|
|
|
|
$ACCOUNT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AccountId' -ErrorAction SilentlyContinue)
|
|
|
|
|
$AGENT_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AgentId' -ErrorAction SilentlyContinue)
|
|
|
|
|
$CUSTOMER_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'CompanyId' -ErrorAction SilentlyContinue)
|
|
|
|
|
$INTEGRATOR_ID = (Get-ItemPropertyValue -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'IntegratorLogin' -ErrorAction SilentlyContinue)
|
2022-04-16 11:00:30 -04:00
|
|
|
LogMsg "AccountID : ${ACCOUNT_ID}"
|
|
|
|
|
LogMsg "AgentID : ${AGENT_ID}"
|
|
|
|
|
LogMsg "CustomerID : ${CUSTOMER_ID}"
|
|
|
|
|
LogMsg "IntegratorID: ${INTEGRATOR_ID}"
|
2022-04-16 11:42:00 -04:00
|
|
|
|
2022-04-16 13:07:35 -04:00
|
|
|
#Download and run the uninstall script
|
|
|
|
|
$UninstallScript = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Uninstall-AteraAgent.ps1'
|
|
|
|
|
Try { Start-Process "powershell.exe" -ArgumentList "-ExecutionPolicy Bypass -Noninteractive -File ""${UninstallScript}""" -Wait }
|
|
|
|
|
Catch { LogErr $_.Exception.Message }
|
2021-02-08 13:39:51 -05:00
|
|
|
}
|
|
|
|
|
|
2022-04-15 13:26:29 -04:00
|
|
|
# Replace the '@' with '%40' - not sure why this is necessary, but it is
|
|
|
|
|
$INTEGRATOR_ID = $INTEGRATOR_ID.Replace('@','%40')
|
|
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Download agent installer
|
2022-03-25 12:57:55 -04:00
|
|
|
Download-File -URL "https://app.atera.com/GetAgent/Msi/?customerId=${CUSTOMER_ID}&integratorLogin=${INTEGRATOR_ID}" -File "${AGENT_INSTALLER}"
|
2021-01-21 12:32:59 -05:00
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Install the agent
|
2022-04-16 13:07:35 -04:00
|
|
|
LogMsg "Installing Atera agent from ""${AGENT_INSTALLER}"""
|
2022-03-25 12:57:55 -04:00
|
|
|
Try { Start-Process "msiexec.exe" -ArgumentList "/i ""${AGENT_INSTALLER}"" /qn /norestart" -Wait }
|
2021-02-08 16:54:08 -05:00
|
|
|
Catch { LogErr $_.Exception.Message }
|
|
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Delete the agent installer
|
2021-02-08 16:54:08 -05:00
|
|
|
LogMsg "Deleting ""${AGENT_INSTALLER}"""
|
|
|
|
|
Try { Remove-Item $AGENT_INSTALLER -Force }
|
2021-02-08 13:39:51 -05:00
|
|
|
Catch { LogErr $_.Exception.Message }
|
2021-01-21 12:32:59 -05:00
|
|
|
|
2022-04-16 11:00:30 -04:00
|
|
|
If ( $PreviousInstall -and $ACCOUNT_ID -and $AGENT_ID -and $CUSTOMER_ID) {
|
|
|
|
|
LogMsg "Restoring agent information from previous install"
|
|
|
|
|
LogMsg " - Stopping AteraAgent service"
|
2022-04-15 13:26:29 -04:00
|
|
|
Stop-Service -Name 'AteraAgent' -Force
|
2022-04-16 11:00:30 -04:00
|
|
|
LogMsg " - Restoring AgentID and AccountID from previous install"
|
2022-04-15 13:26:29 -04:00
|
|
|
Set-ItemProperty -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AccountId' -Value $ACCOUNT_ID
|
|
|
|
|
Set-ItemProperty -Path 'HKLM:SOFTWARE\ATERA Networks\AlphaAgent' -Name 'AgentId' -Value $AGENT_ID
|
2022-04-16 11:00:30 -04:00
|
|
|
LogMsg " - Starting AteraAgent service"
|
2022-04-15 13:26:29 -04:00
|
|
|
Start-Service -Name 'AteraAgent'
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 11:00:30 -04:00
|
|
|
}
|
2021-01-21 12:32:59 -05:00
|
|
|
|
2022-03-25 14:18:19 -04:00
|
|
|
# Delete this script
|
2021-11-18 20:14:45 -05:00
|
|
|
Remove-Item $MyInvocation.MyCommand.Path -Force
|