Files
management-scripts/Install-AteraAgent.ps1
T

55 lines
2.2 KiB
PowerShell
Raw Normal View History

param(
2022-03-25 14:18:19 -04:00
[Parameter(Mandatory=$true)][int]$CUSTOMER_ID=1,
[Parameter(Mandatory=$true)][string]$INTEGRATOR_ID,
[Parameter(Mandatory=$false)][string]$AGENT_FILENAME="AteraAgentSetup.msi",
2021-02-03 09:58:32 -05:00
[Parameter(Mandatory=$false)][switch]$FORCE
)
2022-03-25 14:18:19 -04:00
# Replace the '@' with '%40' - not sure why this is necessary, but it is
2022-03-25 12:57:55 -04:00
$INTEGRATOR_ID = $INTEGRATOR_ID.Replace('@','%40')
2022-03-25 14:18:19 -04:00
# Source the Tools.ps1 script
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
$AGENT_INSTALLER = '{0}{1}' -f (GetTempPath), $AGENT_FILENAME
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") )
{ $INSTALL = $false ; $PreviousInstall = $true } Else { $INSTALL = $true ; $PreviousInstall = $false }
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 ) {
2022-03-25 14:18:19 -04:00
# Uninstall if $FORCE is true
2021-02-08 16:36:42 -05:00
If ( $PreviousInstall ) {
LogMsg "Uninstalling previously installed agent"
$UninstallScript = Download-File -URL 'https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Uninstall-AteraAgent.bat'
Try { Start-Process "cmd.exe" -ArgumentList "/c ""${UninstallScript}""" -Wait }
Catch { LogErr $_.Exception.Message }
Try { Remove-Item $UninstallScript -Force }
Catch { LogErr $_.Exception.Message }
}
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}"
2022-03-25 14:18:19 -04:00
# Install the agent
LogMsg "Installing Atera agent"
2022-03-25 12:57:55 -04:00
Try { Start-Process "msiexec.exe" -ArgumentList "/i ""${AGENT_INSTALLER}"" /qn /norestart" -Wait }
Catch { LogErr $_.Exception.Message }
2022-03-25 14:18:19 -04:00
# Delete the agent installer
LogMsg "Deleting ""${AGENT_INSTALLER}"""
Try { Remove-Item $AGENT_INSTALLER -Force }
Catch { LogErr $_.Exception.Message }
} Else { LogMsg "Atera agent is already installed on this endpoint." }
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