Trying to uninstall software

Welcome Forums General PowerShell Q&A Trying to uninstall software

This topic contains 5 replies, has 5 voices, and was last updated by

6 months ago.

  • Author
  • #134028

    Topics: 9
    Replies: 15
    Points: 12
    Rank: Member


    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?


  • #134067

    Senior Moderator
    Topics: 8
    Replies: 953
    Points: 3,021
    Helping Hand
    Rank: Community Hero

    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
  • #134079

    Topics: 6
    Replies: 55
    Points: 356
    Helping Hand
    Rank: Contributor

    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.

  • #134358

    Topics: 1
    Replies: 9
    Points: 133
    Rank: Participant

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


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


  • #134418

    Topics: 0
    Replies: 1
    Points: 7
    Rank: Member

    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.

  • #134855

    Topics: 6
    Replies: 55
    Points: 356
    Helping Hand
    Rank: Contributor

    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'

The topic ‘Trying to uninstall software’ is closed to new replies.