From a6d1172bfd2a81bc46874d94d2c8aafc4e85d290 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Thu, 10 Nov 2022 19:29:55 -0500 Subject: [PATCH] delete temp directory if already exists --- Install-ESETManagementAgent.ps1 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Install-ESETManagementAgent.ps1 b/Install-ESETManagementAgent.ps1 index 932397c..503a2d3 100644 --- a/Install-ESETManagementAgent.ps1 +++ b/Install-ESETManagementAgent.ps1 @@ -6,6 +6,13 @@ LogMsg "Creating: ${TEMPDIR}" Try { New-Item -Path $TEMPDIR -ItemType Directory -Force -ErrorAction Stop } Catch { LogErr $_.Exception.Message ; Exit } +# Recursively delete $TEMPDIR if it already exists +If ( Test-Path $TEMPDIR ) { + LogMsg """${TEMPDIR}"" already exists and will be deleted" + Try { Remove-Item -Path $TEMPDIR -Recurse -Force } + Catch { LogErr $_.Exception.Message } +} + # Write $CONFIG to install_config.ini Try { $CONFIG | Out-File -FilePath "${TEMPDIR}\install_config.ini" -Force -ErrorAction Stop } Catch { LogMsg "Cannot write configuration file! This script will exit." ; LogErr $_.Exception.Message ; Exit }