initial commit
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user