Trying to uninstall software


I’m trying to uninstall software via powershell and have the following code:


$SoftVer = Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
Get-ItemProperty |
Where-Object {$_.DisplayName -match “avira” } |
Select-Object -Property DisplayName, UninstallString

ForEach ($ver in $SoftVer) {

If ($ver.UninstallString) {

$uninst = $ver.UninstallString
& cmd c/ “$uninst”



It just runs and runs without doing anything. The result of $SoftVer is:

DisplayName UninstallString

Avira Software Updater MsiExec.exe /X{D4F0629A-3F4A-4098-ADFE-6F3551762251}
Avira “C:\ProgramData\Package Cache{f71ab662-e492-44ad-9c93-e995ad4afb95}\Avira.OE.Setup.Bundle.exe” /uninstall

Has anyone any tips as to where I’m going wrong?


not sure, but you could wait for the first one to get uninstalled before attempting the next one.

If ($ver.UninstallString) {
    $FilePath = ($ver.UninstallString -split './')[0]
    $Argument = ($ver.UninstallString -split ' ')[1]
    Start-Process -FilePath $FilePath -Argument "/$Argument" -Wait

Sometimes it does not work in remote sessions or it needs an elevated command prompt.

Did you have a look inside the Setup and Application event logs?
Usually you have some information there about software installation and uninstallation.

You could try uninstalling it by calling the Uninstall method on a WMI object


$app = get-wmiobject -class WIN32_Product | where {$ -match "avira"}


Not having worked with its uninstaller, I’d have to ask if the uninstaller requires user input. Uninstall strings aren’t always automatic and many times requires additional user input or additional command line parameters. Easiest way to determine this is to just open up an administrative shell and execute whatever is in the uninstall key. If it requires you to move forward, you need to figure out what additional parameters it needs.

On Windows 10 you can do:

Get-Package -Name "*Avira*" | Uninstall-Package

Again, only works if the uninstall string doesn’t need additional parameters to automate the uninstaller.

Adam Bertran made a very good module named PSSoftware and which is available on the PowerShell Gallery.
You can use it for inventory with


But it has also several cmdlets for uninstalling software


For example, after finding the software’s GUID with Get-InstalledSoftware, you can uninstall it with the following command line

Uninstall-WindowsInstallerPackageWithMsiexec -Guid '{064A5FA2-8C86-4512-AD36-1EF114CCF58E}' -MsiExecSwitches '/qn'