2022-10-17 13:22:41 -04:00
|
|
|
# NOTE: The $CONFIG variable must be set by the calling script
|
2022-09-06 11:41:22 -04:00
|
|
|
|
2024-03-08 20:39:22 -05:00
|
|
|
# Check whether agent is already installed
|
2024-01-19 21:39:28 -05:00
|
|
|
If ( Test-Path "${Env:ProgramFiles}\ESET\RemoteAdministrator\Agent\ERAAgent.exe" ) {
|
2024-03-08 20:39:22 -05:00
|
|
|
|
|
|
|
|
# End the script if no errors are found in the status log
|
|
|
|
|
If ( !(Select-String -Path "${Env:ProgramData}\ESET\RemoteAdministrator\Agent\EraAgentApplicationData\Logs\status.html" -CaseSensitive -Pattern 'Error:' -Quiet) ) {
|
|
|
|
|
Microsoft.Powershell.Utility\Write-Output "ESET agent is already installed and no errors were found. This script will now exit."
|
|
|
|
|
Return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Write-Output "ESET agent is already installed, but errors were found in the status log. This script will continue and attempt to reinstall the agent."
|
2024-01-19 21:39:28 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-10 19:33:32 -05:00
|
|
|
# Set path to temp directory
|
2023-10-05 12:47:08 -04:00
|
|
|
$TEMPDIR = '{0}eset-protect-deployment' -f (Get-TempPath)
|
2022-10-17 13:22:41 -04:00
|
|
|
|
2022-11-10 19:29:55 -05:00
|
|
|
# Recursively delete $TEMPDIR if it already exists
|
|
|
|
|
If ( Test-Path $TEMPDIR ) {
|
2023-10-05 13:11:38 -04:00
|
|
|
Write-Output """${TEMPDIR}"" already exists and will be deleted"
|
2022-11-10 19:46:37 -05:00
|
|
|
Try { Remove-Item -Path $TEMPDIR -Recurse -Force -ErrorAction SilentlyContinue }
|
2023-10-05 13:17:18 -04:00
|
|
|
Catch { Write-Error $_.Exception.Message }
|
2022-11-10 19:29:55 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-10 19:33:32 -05:00
|
|
|
# Create $TEMPDIR
|
2023-10-05 13:11:38 -04:00
|
|
|
Write-Output "Creating: ${TEMPDIR}"
|
2022-11-10 19:33:32 -05:00
|
|
|
Try { New-Item -Path $TEMPDIR -ItemType Directory -Force -ErrorAction Stop }
|
2024-03-08 20:39:22 -05:00
|
|
|
Catch { Write-Error $_.Exception.Message ; Return }
|
2022-11-10 19:33:32 -05:00
|
|
|
|
2022-10-17 13:22:41 -04:00
|
|
|
# Write $CONFIG to install_config.ini
|
2022-11-11 15:10:59 -05:00
|
|
|
Try { $CONFIG | WriteToFile_UTF8NoBOM -FilePath "${TEMPDIR}\install_config.ini" }
|
2024-03-08 20:39:22 -05:00
|
|
|
Catch { Write-Output "Cannot write configuration file! This script will exit." ; Write-Error $_.Exception.Message ; Return }
|
2022-10-17 13:22:41 -04:00
|
|
|
|
|
|
|
|
# Get bitness of endpoint and set $AGENTNAME
|
|
|
|
|
If ( Is64bit ) { $AGENTNAME = "agent_x64.msi" } Else { $AGENTNAME = "agent_x86.msi" }
|
2022-09-02 15:16:37 -04:00
|
|
|
|
|
|
|
|
# Download the installer
|
2022-10-17 13:22:41 -04:00
|
|
|
$INSTALLER = "${TEMPDIR}\${AGENTNAME}"
|
2022-11-11 15:10:59 -05:00
|
|
|
$URL = 'https://download.eset.com/com/eset/apps/business/era/agent/latest/{0}' -f $AGENTNAME
|
2023-10-05 13:11:38 -04:00
|
|
|
Write-Output "Downloading ESET Management Agent"
|
2022-10-17 13:22:41 -04:00
|
|
|
Download-File -URL $URL -File $INSTALLER
|
2022-09-02 15:16:37 -04:00
|
|
|
|
|
|
|
|
# Install the app
|
2023-10-05 13:11:38 -04:00
|
|
|
Write-Output "Installing ESET Management Agent from ""${INSTALLER}"""
|
2022-11-11 13:37:50 -05:00
|
|
|
Try { Start-Process "msiexec.exe" -ArgumentList "/i ${INSTALLER} /qn /norestart /log installer.log" -Wait }
|
2023-10-05 13:17:18 -04:00
|
|
|
Catch { Write-Error $_.Exception.Message }
|
2022-09-02 15:16:37 -04:00
|
|
|
|
|
|
|
|
# Delete the installer
|
2023-10-05 13:11:38 -04:00
|
|
|
Write-Output "Deleting temp directory and its contents"
|
2022-11-11 15:20:57 -05:00
|
|
|
Try { Remove-Item -Path $TEMPDIR -Recurse -Force -ErrorAction SilentlyContinue }
|
2023-10-05 13:17:18 -04:00
|
|
|
Catch { Write-Error $_.Exception.Message }
|