Last active
November 5, 2022 07:20
-
-
Save tony199555/c228f8d80e8324500fdba8b8ea435cf5 to your computer and use it in GitHub Desktop.
Search Registry for ESET Uninstall String and Uninstall Using Search Result with Output Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$site = "CHANGE_THIS" # Example: $site = "AHA" | |
$eset_pw = "YOUR_PASSWORD" | |
$pw_list = @{example1 = "example1" ; example2 = "example2" } #For multiple site use | |
if ([string]::IsNullOrEmpty($eset_pw)) { | |
$eset_pw = $pw_list.$site | |
} | |
function Search-Registry { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory, Position = 0, ValueFromPipelineByPropertyName)] | |
[Alias("PsPath")] | |
# Registry path to search | |
[string[]] $Path, | |
# Specifies whether or not all subkeys should also be searched | |
[switch] $Recurse, | |
[Parameter(ParameterSetName = "SingleSearchString", Mandatory)] | |
# A regular expression that will be checked against key names, value names, and value data (depending on the specified switches) | |
[string] $SearchRegex, | |
[Parameter(ParameterSetName = "SingleSearchString")] | |
# When the -SearchRegex parameter is used, this switch means that key names will be tested (if none of the three switches are used, keys will be tested) | |
[switch] $KeyName, | |
[Parameter(ParameterSetName = "SingleSearchString")] | |
# When the -SearchRegex parameter is used, this switch means that the value names will be tested (if none of the three switches are used, value names will be tested) | |
[switch] $ValueName, | |
[Parameter(ParameterSetName = "SingleSearchString")] | |
# When the -SearchRegex parameter is used, this switch means that the value data will be tested (if none of the three switches are used, value data will be tested) | |
[switch] $ValueData, | |
[Parameter(ParameterSetName = "MultipleSearchStrings")] | |
# Specifies a regex that will be checked against key names only | |
[string] $KeyNameRegex, | |
[Parameter(ParameterSetName = "MultipleSearchStrings")] | |
# Specifies a regex that will be checked against value names only | |
[string] $ValueNameRegex, | |
[Parameter(ParameterSetName = "MultipleSearchStrings")] | |
# Specifies a regex that will be checked against value data only | |
[string] $ValueDataRegex | |
) | |
begin { | |
switch ($PSCmdlet.ParameterSetName) { | |
SingleSearchString { | |
$NoSwitchesSpecified = -not ($PSBoundParameters.ContainsKey("KeyName") -or $PSBoundParameters.ContainsKey("ValueName") -or $PSBoundParameters.ContainsKey("ValueData")) | |
if ($KeyName -or $NoSwitchesSpecified) { $KeyNameRegex = $SearchRegex } | |
if ($ValueName -or $NoSwitchesSpecified) { $ValueNameRegex = $SearchRegex } | |
if ($ValueData -or $NoSwitchesSpecified) { $ValueDataRegex = $SearchRegex } | |
} | |
MultipleSearchStrings { | |
# No extra work needed | |
} | |
} | |
} | |
process { | |
foreach ($CurrentPath in $Path) { | |
Get-ChildItem $CurrentPath -Recurse:$Recurse | | |
ForEach-Object { | |
$Key = $_ | |
if ($KeyNameRegex) { | |
Write-Verbose ("{0}: Checking KeyNamesRegex" -f $Key.Name) | |
if ($Key.PSChildName -match $KeyNameRegex) { | |
Write-Verbose " -> Match found!" | |
return [PSCustomObject] @{ | |
Key = $Key | |
Reason = "KeyName" | |
} | |
} | |
} | |
if ($ValueNameRegex) { | |
Write-Verbose ("{0}: Checking ValueNamesRegex" -f $Key.Name) | |
if ($Key.GetValueNames() -match $ValueNameRegex) { | |
Write-Verbose " -> Match found!" | |
return [PSCustomObject] @{ | |
Key = $Key | |
Reason = "ValueName" | |
} | |
} | |
} | |
if ($ValueDataRegex) { | |
Write-Verbose ("{0}: Checking ValueDataRegex" -f $Key.Name) | |
if (($Key.GetValueNames() | ForEach-Object { $Key.GetValue($_) }) -match $ValueDataRegex) { | |
Write-Verbose " -> Match!" | |
return [PSCustomObject] @{ | |
Key = $Key | |
Reason = "ValueData" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
#ESET Endpoint Security | |
$ees_string = (Search-Registry -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* -SearchRegex "ESET Endpoint" -ValueData | Select-Object -ExpandProperty "Key") | |
$ees_us = $ees_string -replace [Regex]::Escape("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"), "" | |
if (-not [string]::IsNullOrEmpty($ees_us)) { | |
$Execute = "msiexec.exe" | |
$parameters = "/x $ees_us /qn /norestart /l*v C:\Windows\Temp\EESUninstall.log PASSWORD=$eset_pw" | |
$uninstall_process = (Start-Process -FilePath $Execute -ArgumentList $parameters -Wait -PassThru) | |
$uninstall_process.WaitForExit(); | |
if ($uninstall_process.ExitCode -eq 3010) { | |
Write-Host "ESET Endpoint Security UNINSTALLED, restart required" | |
} | |
else { | |
Write-Host "ESET Endpoint Security uninstall FAILED" | |
} | |
} | |
else { | |
Write-Host "ESET Endpoint Security NOT installed" | |
} | |
#ESET Management Agent | |
$ema_string = (Search-Registry -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* -SearchRegex "ESET Management" -ValueData | Select-Object -ExpandProperty "Key") | |
$ema_us = $ema_string -replace [Regex]::Escape("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"), "" | |
if (-not [string]::IsNullOrEmpty($ema_us)) { | |
$Execute = "msiexec.exe" | |
$parameters = "/x $ema_us /qn /norestart /l*v C:\Windows\Temp\EMAUninstall.log" | |
$uninstall_process = (Start-Process -FilePath $Execute -ArgumentList $parameters -Wait -PassThru) | |
$uninstall_process.WaitForExit(); | |
if ($uninstall_process.ExitCode -eq 0) { | |
Write-Host "ESET Management Agent UNINSTALLED" | |
Exit | |
} | |
else { | |
Write-Host "ESET Management Agent uninstall FAILED" | |
Exit | |
} | |
} | |
else { | |
Write-Host "ESET Management Agent NOT installed" | |
Exit | |
} | |
#CHANGE SITE NAME AT THE TOP!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment