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

 
Participant
2 months ago.

  • Author
    Posts
  • #134028

    Participant
    Points: 12
    Rank: Member

    hi,

    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?

    Thanks

  • #134067

    Participant
    Points: 1,620
    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

    Participant
    Points: 325
    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

    Participant
    Points: 60
    Rank: Member

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

     

    $app = get-wmiobject -class WIN32_Product | where {$_.name -match "avira"}
    $app.Uninstall()

     

  • #134418

    Participant
    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

    Participant
    Points: 325
    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

    Get-InstalledSoftware

    But it has also several cmdlets for uninstalling software

    Uninstall-InstallShieldPackage
    Uninstall-ViaMsizap
    Uninstall-WindowsInstallerPackage
    Uninstall-WindowsInstallerPackageWithMsiexec
    Uninstall-WindowsInstallerPackageWithMsiModule
    

    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'
    

You must be logged in to reply to this topic.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort