Does Uninstall-ADTApplication change incorrect MSI parameter?

As per the title, does this function check for incorrect MSI parameters and modify them?

I’ve encountered some apps that have UNinstall strings that calls “msiexec /I” instead of “msiexec /X”

I am currently using this piece of code but would rather remove it if it’s already being done (albeit with better code):

## <Perform Pre-Installation tasks here>
	$partialAppName = "*$($adtSession.AppName)*"

    $regPaths = @("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall","HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall")

    foreach ($regPath in $regPaths) {
        # Get all subkeys (applications) from the registry path
        $keys = Get-ChildItem -Path $regPath

        foreach ($key in $keys) {
            # Get the display name and uninstall string
            $displayName = (Get-ItemProperty -Path $key.PSPath -Name "DisplayName" -ErrorAction SilentlyContinue).DisplayName
            $uninstallString = (Get-ItemProperty -Path $key.PSPath -Name "UninstallString" -ErrorAction SilentlyContinue).UninstallString

            # Check for partial match
            if (($displayName -like $partialAppName) -and ($uninstallString -ne $null)) {
                if ($uninstallString.StartsWith("msiexec.exe /i",'CurrentCultureIgnoreCase') ) {
                    $msiProductCode = $uninstallString -replace "msiexec.exe /i"
                    Start-ADTMsiProcess -Action 'Uninstall' -FilePath "$($msiProductCode)"
                } else {
                    $uninstallString = $uninstallString -replace '"'
                    Start-ADTProcess -FilePath "$($uninstallString)" -ArgumentList '/S'
                }
            }
        }
    }

You can look at the sauce code for that function here: PSAppDeployToolkit/src/PSAppDeployToolkit/Public/Uninstall-ADTApplication.ps1 at 79684ff4fe1c19ead59086c941f449d82501df18 · PSAppDeployToolkit/PSAppDeployToolkit · GitHub

It sends the InstalledApplication object straight through to Start-ADTMsiProcess to handle. That function will grab the ProductCode and do a classic msiexec.exe /x {SomeLongAppGuid}.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.