Search code examples
windowspowershellwmiuninstallationget-wmiobject

Uninstalling software (ArcFM) with powershell with no Remove option in MSI


Summary of situation

I have some third party extension software for ArcGIS that I need to be able to uninstall with a powershell script. I have successfully installed and uninstalled a suite of software using the AppDeployToolkit for powershell but I am stuck trying to uninstall this one program. I am able to uninstall everything by running the MSI with an "Uninstall parameter". Unfortunately, this third party extension has no uninstall/remove option in the msi (no repair, remove, or uninstall options when I run it manually). It simply just tries to install again. I am, however, able to successfully uninstall from the 'Apps and Features' program GUI tool in windows.

Here are the things i've tried:

attempt A: Using the AppDeployToolkit

Execute-MSI -Action "Uninstall" -Path "Path\To\ArcFM.msi"

Output: Error: Application is already installed

attempt B: using WMI Object

$app = get-wmiobject -class win32_product |where-object {$_.Name -Match "ArcFM Solution Desktop*"}
$app.Uninstall()

Output: 1603 error (this is the error code for an installation error)

attempt C: using Uninstall-Package

$app = get-package -provider programs -includewindowsinstaller -name "ArcFM*
Uninstall-Package -Name $app

Output: Asks me to automatically install Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll. When I enter Y to automatically install I get this error...

Uninstall-Package : No package found for 'Microsoft.PackageManagement.Packaging.SoftwareIdentity'.
At line:1 char:1
+ Uninstall-Package -Name $arcfm2
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
    + FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage

My Question

My overall questions is "How can I uninstall this software from powershell?"

But more specifically....

I CAN uninstall it from 'Apps and Feautures'. So when I use the GUI to do that, how exactly is windows executing the uninstall? It's not using the MSI and apparently not using wmi-objects either. It can't be using Uninstall-Package because it's not even installed on the machine. Is there a way for me to execute the same process that add/remove programs executes to uninstall from powershell? Is there a different way to uninstall software that I have missed?


Solution

  • In a previous life, I used a fun product called PDQ to manage application deployments. One of the cool features of the product was that it pulled Product GUIDs for installed applications and built uninstallers for them. Here's how it did it:

    # GUID is not unique across multiple computers, so pull it from the machine
    $gui = Get-WMIObject Win32_Product | Where-Object -Property name -like "ArcFM*" | Select-Object -ExpandProperty IdentifyingNumber
    # Use MSIexec.exe /x = uninstall /QN = silent
    msiexec /x $guid
    

    Hopefully that helps!

    UPDATE I am editing the answer so that I can accept it. Removing th e /QN parameter from the final command. Placing it after the $guid variable may work too.