From c33adb91bd1df371e1df5a99d1cc58c99428af37 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 8 Mar 2024 20:39:22 -0500 Subject: [PATCH] reinstall if errors are found in status log --- Install-ESETManagementAgent.ps1 | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/Install-ESETManagementAgent.ps1 b/Install-ESETManagementAgent.ps1 index aa69bad..027c96c 100644 --- a/Install-ESETManagementAgent.ps1 +++ b/Install-ESETManagementAgent.ps1 @@ -1,9 +1,15 @@ # NOTE: The $CONFIG variable must be set by the calling script -# Exit this script if agent is already installed +# Check whether agent is already installed If ( Test-Path "${Env:ProgramFiles}\ESET\RemoteAdministrator\Agent\ERAAgent.exe" ) { - Microsoft.Powershell.Utility\Write-Output "ESET agent is already installed. This script will now exit." - Return + + # 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." } # Set path to temp directory @@ -19,11 +25,11 @@ If ( Test-Path $TEMPDIR ) { # Create $TEMPDIR Write-Output "Creating: ${TEMPDIR}" Try { New-Item -Path $TEMPDIR -ItemType Directory -Force -ErrorAction Stop } -Catch { Write-Error $_.Exception.Message ; Exit } +Catch { Write-Error $_.Exception.Message ; Return } # Write $CONFIG to install_config.ini Try { $CONFIG | WriteToFile_UTF8NoBOM -FilePath "${TEMPDIR}\install_config.ini" } -Catch { Write-Output "Cannot write configuration file! This script will exit." ; Write-Error $_.Exception.Message ; Exit } +Catch { Write-Output "Cannot write configuration file! This script will exit." ; Write-Error $_.Exception.Message ; Return } # Get bitness of endpoint and set $AGENTNAME If ( Is64bit ) { $AGENTNAME = "agent_x64.msi" } Else { $AGENTNAME = "agent_x86.msi" }