From 33960214fd61b428ebb0b5118e6ec0973a64c893 Mon Sep 17 00:00:00 2001 From: David Yoder Date: Mon, 22 Apr 2024 22:27:37 -0400 Subject: [PATCH] initial commit --- Remove-AllESETProducts.ps1 | 59 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Remove-AllESETProducts.ps1 diff --git a/Remove-AllESETProducts.ps1 b/Remove-AllESETProducts.ps1 new file mode 100644 index 0000000..6050739 --- /dev/null +++ b/Remove-AllESETProducts.ps1 @@ -0,0 +1,59 @@ +# Are we running in Safe Mode? +Switch ( ($Env:SAFEBOOT_OPTIONS).ToUpper() -eq "NETWORK" ) { + + # We're in Safe Mode + $true { + # Download the ESET Uninstaller + Write-Output "Downloading ESET Uninstaller to: ${ESETUninstaller}" + $ESETUninstallerURL = "https://download.eset.com/computer/uninstaller/esetuninstaller.exe" + Download-File -URL $ESETUninstallerURL -File $ESETUninstaller + If ( !(Test-Path $ESETUninstaller) ) { Write-Error "ERROR: ESET Uninstaller could not be downloaded, this script will exit" ; Return } + + # Backup network interfaces and settings + $InterfacesFile = "${Global:OutputDirectory}\interfaces.dat" + If ( Test-Path $InterfacesFile ) { Write-Output "Removing existing interface export: ${InterfacesFile}" ; Remove-Item -Path $InterfacesFile -Force } + Write-Output "Exporting interfaces to: ${InterfacesFile}" + Try { & netsh.exe -c interface dump | Out-File $InterfacesFile } + Catch { Write-Error "ERROR: Interfaces could not be exported, this script will exit" ; Return } + + # Uninstall all ESET products + Write-Output "Uninstalling all ESET products" + & "cmd.exe /k ""${ESETUninstaller}"" /mode=online /force" + + # Restore network interfaces and settings + If ( Test-Path $InterfacesFile ) { + Write-Output "Restoring interfaces from export: ${InterfacesFile}" + Try { & netsh.exe exec $InterfacesFile } + Catch { Write-Error "ERROR: Interfaces could not be restored!" } + } + + # Ensure safe mode is disabled + Write-Output "Disabling safe mode" + $command = "${Env:SystemRoot}\System32\bcdedit.exe" + $params = "/deletevalue {default} safeboot".Split(" ") + Try { & "${command}" $params } + Catch { + If ( $_.Exception.Message -match "Element not found" ) { Write-Output "Safe mode is already disabled" } + Else { Write-Error "ERROR: could not disable safe mode, manual intervention may be required" } + } + + # Reboot into normal mode + Write-Output "Rebooting into normal mode" + & "${Env:SystemRoot}\System32\shutdown.exe" -r -f -t 5 + } + + # We're not in Safe Mode + $false { + + # Schedule this script to run in Safe Mode + $key = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Runonce' + Try { New-ItemProperty -Path $key -Name '*Remove-AllESETProducts' -Value 'powershell.exe -ExecutionPolicy Bypass -Command {. $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString("https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1"))) ; Run-Script -LivePSScript Remove-AllESETProducts}' -PropertyType String -Force } + Catch { Write-Error "ERROR: could not configure reboot into normal mode" ; Return } + + # Restart the computer into Safe Mode with Networking + Run-Script -LivePSScript Fix-RebootIntoSafeMode + } +} + + +