Uninstall the previous version of the application being installed

I have an application that insists that the previous version be removed before the new one can be installed. My cunning plan was to provide the GUIDs for the new version and the previous version and attempt to uninstall each of them, like so:

$GUIDs = @("{25D5233F-C473-5C50-8253-53FB6DFF2581}","{C66139FA-C7F6-4980-A696-DC64ABC6BC3F}")
ForEach ($GUID in $GUIDs)
{
Execute-MSI -Action ‘Uninstall’ -Path $GUID -SkipMSIAlreadyInstalledCheck
}

It fails to uninstall the previous version with The MSI is not installed on this system. Skipping action [Uninstall].

Am I doing something wrong? Should I just switch to Execute-Process and call msiexec.exe? Any other suggestions?

Why are you passing the GUID of both the old and new MSI to the foreach loop? Why not just use the display name to remove the old? And just use the path to the new MSI file?

Remove-MSIApplications -Name ‘OldApplicationNameHere’

Execute-MSI -Action Install -Path ‘NewMSINameHere.msi’

Get rid of the -SkipMSIAlreadyInstalledCheck parameter…

I’ll tell you why am I passing the GUID. Since the Execute-MSI has an Action parameter, the thought of looking for another command that actually does what I want, never occurred to me. TL;DR I’m a fool!

Jim, I want to thank you for your answer. This week has been fraught with answers (in other forums) that, while technically answers, were not answers to the questions I asked. You, on the other hand, gave me exactly what I needed. If I could up-vote you, I would.

Thanks again.

JT, glad I was able to help. Thanks for the compliment.

Jim

Good day! You must remove the old version 7z 9.20, before installing the new version 18.06. The problem is that the installer of version 9.20 is packed with NSIS, and the new version is installed through the MSI package. How can I correctly remove the previous version of the software, can I do this? Thanks

Hello

To remove older version which is NSIS file , you need to use uninstall string of installer . For this use Execute-Process and pass the required .exe name (using makensis or installer maybe) with uninstall switch. You cant use Remove-MSIApplications to remove NSIS file. This function only removes MSI applications matching with specified app name provided the uninstall string matches “msiexec”.

This was something I used to uninstall VC++. you may have to modify a bit. it did not have standard uinstall…

Query and UnInstall current version of Microsoft Visual C++ 2015 & 2017

	[String]   $strComptr       = $Env:ComputerName
	[String]   $strLogDir       = $configToolkitLogDir + [Char]92
	[String]   $strVisCPPAppNam = "Microsoft Visual C++ 201* Redistributable*"
	[PsObject] $colVisCPP       = (Get-InstalledApplication -Name $strVisCPPAppNam -Wildcard)
	
	Write-Log -Message "==================================="
	If ($colVisCPP -NE $Null) {
	[Boolean]  $bolVisCPPInstld = $True
	Write-Log -Message "$strVisCPPAppNam is installed"
	ForEach ($objVisCPP In $colVisCPP) {
		If (([System.Version] $objVisCPP.DisplayVersion).Major -GE 14) {
			[String]         $strVisCPPDisNam       = $($objVisCPP.DisplayName)
			[System.Version] $strVisCPPVerson       = $($objVisCPP.DisplayVersion)
			[String]         $strVisCPPUnistlExePth = $($objVisCPP.UninstallString).Substring(0, $($objVisCPP.UninstallString).IndexOf([Char]47) - 2)
			[String]         $strVisCPPUnistlExePth = $strVisCPPUnistlExePth.Replace('"',"")
			[String]         $strVisCPPUnistlParams = "/uninstall /quiet"
			Write-Log -Message "-----------------------------------"
			Write-Log -Message "strVisCPPDisNam: `t$strVisCPPDisNam"
			Write-Log -Message "strVisCPPVerson: `t$strVisCPPVerson"
			Write-Log -Message "strVisCPPUnistlExePth: `t$strVisCPPUnistlExePth"
			Write-Log -Message "strVisCPPUnistlParams: `t$strVisCPPUnistlParams"
			Write-Log -Message "Begin $strVisCPPDisNam v$strVisCPPVerson Uninstall"
			
			[PsObject] $intVisCPPUninstRetVal = Execute-Process -Path $strVisCPPUnistlExePth -Parameters $strVisCPPUnistlParams -ContinueOnError $False -WindowStyle "Hidden" -PassThru:$True -WaitForMsiExec
			
			Write-Log -Message "Exit Code:`t$($intVisCPPUninstRetVal.ExitCode)"
			If (($intVisCPPUninstRetVal.ExitCode -Eq 0) -Or ($intVisCPPUninstRetVal.ExitCode -Eq 3010)) {
				Write-Log -Message "$strVisCPPDisNam v$strVisCPPVerson uninstalled successfully: $($intVisCPPUninstRetVal.ExitCode)"
				}
			Else {
				Write-Log -Message "$strVisCPPDisNam v$strVisCPPVerson encountered an error during uninstallation: $($intVisCPPUninstRetVal.ExitCode)"
				}
			
			Write-Log -Message "If Exit Code 0, $strVisCPPDisNam v$strVisCPPVerson Uninstalled"
			Write-Log -Message "-----------------------------------"
			}
		}
		Write-Log -Message "Exit Code:`t$($intVisCPPUninstRetVal.ExitCode)"
		If (($intVisCPPUninstRetVal.ExitCode -Eq 0) -Or ($intVisCPPUninstRetVal.ExitCode -Eq 3010)) {
			Write-Log -Message "$strVisCPPDisNam v$strVisCPPVerson uninstalled successfully: $($intVisCPPUninstRetVal.ExitCode)"
			}
		Else {
			Write-Log -Message "$strVisCPPDisNam v$strVisCPPVerson encountered an error during uninstallation: $($intVisCPPUninstRetVal.ExitCode)"
			}
		}