Remove-MSIApplications not working for me

I’, trying to uninstall a application called “XYZ 10.2” with

Remove-MSIApplications -Name “XYZ” -Wildcard

but it does not work. I found this in the logs:

Skipping removal of application [XYZ 10.2] because uninstall string [“C:\Program Files (x86)\XYZ\XYZ102\unins000.exe”] does not match “msiexec”.

It looks like that he founds a installed Version , but it is not an msiexec uninstallation method.

Any suggestions if it is possible to use such “uninstall exe” files ?

Try it without the -wildcard, it should still uninstall if only part of the name is specified.

Remove-MSIApplications as the name suggests only removes applications that use an MSI installer. Your application using an executable installer and so cannot be removed using the Remove-MSIApplications function. You have a couple of options, the simplest one if you know where the uninstall.exe is located is to simply use Execute-Process function to uninstall the software eg.

If(Testpath -Path "$envProgramFilesX86\XYZ\XYZ102\uninst000.exe"){
 Execute-Process -Path "$envProgramFilesX86\XYZ\XYZ102\uninst000.exe"-Parameters '/silent'
}

I have wrapped this in If statement so that the script doesnt error out if the uninst000.exe doesnt exist.

The second option is to create a custom registry search function to look for the application UninstallString then run the uninstall with the required silent switches. eg.

$RegistryKeys = Get-ItemProperty -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | ?{$_.DisplayName -like "XYZ*" -and $_.UninstallString -ne $null}

Foreach($Key in $RegistryKeys){
            If(Test-Path -Path $Key.UninstallString){
                Execute-Process -Path $Key.UninstallString -Parameters '/silent'
                }
        }

If the installation program was 64-bit you would need to repeat this using the 64-bit registry uninstall path.

Note: Based on the name of the uninstaller I am assuming that you are dealing with an Innosetup installer which uses the /silent switch for silent install/uninstall. If not then you’ll need to find the silent switches for whichever installer you are using.

http://www.jrsoftware.org/ishelp/topic_setupcmdline.htm

3 Likes

@PeterP
Get-InstalledApplication will do this already for you. For example:

{
	$appInstalled = Get-InstalledApplication -Name "$appName"
	$appInstalledCount = $(($appInstalled | Measure-Object).Count)
	Write-Log -Message "Detected $appInstalledCount instances of $appName" -Severity 1 -Source $deployAppScriptFriendlyName

	foreach ($appInstallation in $appInstalled) {
		Write-Log -Message "Processing $($appInstallation.DisplayName) $($appInstallation.DisplayVersion)" -Severity 1 -Source $deployAppScriptFriendlyName
		Write-Log -Message "UninstallString: $($appInstallation.UninstallString)" -Severity 1 -Source $deployAppScriptFriendlyName
		# If the uninstallstring has quotes, you need to remove them
		$uninstallString = $appInstallation.UninstallString.Replace('"', "")
		$execProcess = Execute-Process -Path $uninstallString -Parameters "/S" -WindowStyle Hidden -PassThru
		sleep -Seconds 3
		Write-Log -Message "Exit Code: $($execProcess.ExitCode)" -Severity 1 -Source $deployAppScriptFriendlyName
		}
}
1 Like

thanks guys , i will give it a try