diff --git a/Remove-AllESETProducts.ps1 b/Remove-AllESETProducts.ps1 index e04d6aa..8eff6f8 100644 --- a/Remove-AllESETProducts.ps1 +++ b/Remove-AllESETProducts.ps1 @@ -1,6 +1,5 @@ # Are we running in Safe Mode with Networking? -Try { If ( ($Env:SAFEBOOT_OPTIONS).ToUpper() -eq "NETWORK" ) { $InSafeNetMode = $true } Else { $InSafeNetMode = $false } } -Catch { $InSafeNetMode = $false } +If ( (Get-CimInstance -ClassName Win32_ComputerSystem).BootupState.ToLower() -eq "fail-safe with network boot" ) { $InSafeNetMode = $true } Else { $InSafeNetMode = $false } Switch ( $InSafeNetMode ) { @@ -8,7 +7,7 @@ Switch ( $InSafeNetMode ) { $true { # Download the ESET Uninstaller Write-Output "Downloading ESET Uninstaller to: ${ESETUninstaller}" - $ESETUninstallerURL = "https://download.eset.com/computer/uninstaller/esetuninstaller.exe" + $ESETUninstallerURL = "https://download.eset.com/com/eset/tools/installers/eset_apps_remover/latest/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 } @@ -50,8 +49,9 @@ Switch ( $InSafeNetMode ) { # 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 } + $encodedCommand = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes('. $([Scriptblock]::Create((New-Object Net.WebClient).DownloadString("https://dev.emberkom.com/emberkom/management-scripts/raw/branch/master/Tools.ps1"))) ; Run-Script -LivePSScript Remove-AllESETProducts')) + Try { New-ItemProperty -Path $key -Name '*Remove-AllESETProducts' -Value "powershell.exe -ExecutionPolicy Bypass -EncodedCommand ${encodedCommand}" -PropertyType String -Force } + Catch { Write-Error "ERROR: could not configure Remove-AllESETProducts script to run at next boot" ; Return } # Restart the computer into Safe Mode with Networking Run-Script -LivePSScript Fix-RebootIntoSafeMode