Uninstall app test works but not when loaded into SCCM or Intune

I’m trying to only uninstall an application called Smartview, however it will not uninstall (uses /x parameter). I have ran/tested the script multiple different ways in the psappdeploy script which all have worked when running locally to test.
Once I upload to either SCCM or Intune (intune winap32 converter), its as if they completely skip over this verbiage to uninstall. I tried to include the uninstall language (pasted below) in the pre-install without luck then tried the post-install without luck.

One thing I was struggling to get working properly was having the .ps1 script to to do the uninstall located in the SupportFiles folder, then calling out that ps1 to use that in the pre or Post install section. I know it involves the $($adtSession.DirSupportFiles)\filename.xxx but can’t seem to figure out what I’m doing wrong.

Any tips would be great. Maybe I’m going about this the wrong way…Below is my script to uninstall smartview.

# Define the name and version of the application to be removed
$appName = "Oracle Smart View 64-bit for Office"
$appVersion = "11.1.2.5.720"
 
# Method 1: Check registry for installed software (more reliable than Win32_Product)
Write-Output "Searching for $appName version $appVersion..."
 
$uninstallKeys = @(
    "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
    "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
 
$app = Get-ItemProperty $uninstallKeys | 
    Where-Object { $_.DisplayName -like "*$appName*" -and $_.DisplayVersion -eq $appVersion } |
    Select-Object -First 1
 
if ($app) {
    $uninstallString = $app.UninstallString
    $guid = $null
    # Check if it has a GUID-style uninstall string (common for MSI packages)
    if ($uninstallString -match "{[0-9A-F-]+}") {
        $guid = $matches[0]
        Write-Output "Found application with GUID: $guid"
        # Uninstall using MsiExec
        Write-Output "Attempting to uninstall $appName version $appVersion..."
        $process = Start-Process -FilePath "msiexec.exe" -ArgumentList "/x $guid /qn" -Wait -PassThru
        if ($process.ExitCode -eq 0) {
            Write-Output "$appName version $appVersion has been uninstalled successfully."
        } else {
            Write-Output "Uninstallation failed with exit code: $($process.ExitCode)"
        }
    }
    # Check if it uses a direct executable uninstaller
    elseif ($uninstallString -ne $null) {
        Write-Output "Found application with uninstall string: $uninstallString"
        # Some uninstall strings include parameters, others don't
        if ($uninstallString -match '^"(.+?)"(.*)$') {
            $uninstallExe = $matches[1]
            $uninstallArgs = $matches[2]
            if (-not $uninstallArgs.Contains("/qn")) {
                $uninstallArgs += " /qn"
            }
        } else {
            $uninstallExe = $uninstallString
            $uninstallArgs = "/qn"
        }
        # Run the uninstaller
        Write-Output "Attempting to uninstall using: $uninstallExe $uninstallArgs"
        $process = Start-Process -FilePath $uninstallExe -ArgumentList $uninstallArgs -Wait -PassThru
        if ($process.ExitCode -eq 0) {
            Write-Output "$appName version $appVersion has been uninstalled successfully."
        } else {
            Write-Output "Uninstallation failed with exit code: $($process.ExitCode)"
        }
    } else {
        Write-Output "Found $appName version $appVersion, but couldn't determine how to uninstall it."
    }
} else {
    Write-Output "$appName version $appVersion is not found on this system."
    # Optional: List similar applications that might match
    Write-Output "`nSimilar applications found on this system:"
    Get-ItemProperty $uninstallKeys | 
        Where-Object { $_.DisplayName -like "*Oracle*" -or $_.DisplayName -like "*Smart View*" } |
        Select-Object DisplayName, DisplayVersion |
        Format-Table -AutoSize
}

Is the application installed in the user context? This would prevent a script running in the system context from removing the app.

2 Likes

Its done under system. Good check though