Programmatically remove MSFT Security Essentials Anti-Virus from XP and Win7 machines

Solution 1:

It looks to me like you've got more than one product being returned by the Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | ?{$_.GetValue("DisplayName") -like "Microsoft Security Essentials" } cmdlet, and your script it falling over because it only expects one.

Try this modified script which loops over each returned object and executes the uninstall command for the product. I've also changed the /s switch on msiexec to /quiet as that looks to be compatible with more versions of Windows.

$UninstallString = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | ?{$_.GetValue("DisplayName") -like "Microsoft Security Essentials" } | ForEach-Object -Process {$_.GetValue("UninstallString") }

foreach($ThisProduct in $UninstallString)
{
    $UninstallCmd = $ThisProduct.split('/')[0].Trim() 
    $UninstallParam = '/' + $ThisProduct.split('/')[1].Trim()
    $UninstallParamQuiet = "/quiet"

    & $UninstallCmd $UninstallParam $UninstallParamQuiet
}

Disclaimer: This answer comes after an awful lot of back and forth in chat to determine the real problem that more than one item was being returned by one of the PowerShell commands.

Solution 2:

Is $UninstallString indeed a string? If not, you may need to cast it to be a string. Also, I don't think that it's null, but you may want to verify that it contains what you think it does after that first step.

Solution 3:

@ECHO OFF

CLS

C:

CD\

CD Program Files\Microsoft Security Client

setup.exe /x /s



EXIT

This works on XP clients, haven't tested on Win7 but as it's just a batch script it should be fine. Obligatory "So easy a $BRAINDEADBIPED could do it!" here.