Application

Get Registry Key UninstallString of an application and uninstall it – PSADT

#get the uninstall string from the 32-bit registry
$uninstallString = Get-ItemProperty 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
    Where-Object { $_.DisplayName -like '*Dell SupportAssist OS Recovery Plugin for Dell Update*' } |
    Select-Object -First 1 -ExpandProperty UninstallString

#proceed only if uninstall string was found
if ($uninstallString) {
    Write-Log -Message "Uninstall string found: $uninstallString" -Severity 1

    #use PowerShell's built-in parsing to split the string
    $parts = $uninstallString -split '\s+(?=(?:[^"]*"[^"]*")*[^"]*$)', 2

    if ($parts.Count -ge 1) {
        $exePath = $parts[0].Trim('"')
        $exeParams = if ($parts.Count -eq 2) { $parts[1] + ' /quiet' } else { '/quiet' }

        Execute-Process -Path $exePath -Parameters $exeParams -WindowStyle 'Hidden'
    } else {
        Write-Log -Message "Failed to parse uninstall string: $uninstallString" -Severity 3
    }
} else {
    Write-Log -Message "Uninstall string not found in 32-bit registry." -Severity 2
}  

Get Registry Key QuietUninstallString or UninstallString of an application and uninstall it – PSADT

#define the target display name
$targetDisplayName = 'Microsoft Visual C++ 2015-2022 Redistributable (x86) - 14.42.34438'

#query the 32-bit registry once
$uninstallEntry = Get-ItemProperty 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*' |
    Where-Object { $_.DisplayName -eq $targetDisplayName } |
    Select-Object -First 1

#try QuietUninstallString first
if ($uninstallEntry.QuietUninstallString) {
    Write-Log -Message "QuietUninstallString found: $($uninstallEntry.QuietUninstallString)" -Severity 1

    $parts = $uninstallEntry.QuietUninstallString -split '\s+(?=(?:[^"]*"[^"]*")*[^"]*$)', 2
    $exePath = $parts[0].Trim('"')
    $exeParams = if ($parts.Count -eq 2) { $parts[1] } else { '' }

    if (Test-Path $exePath) {
        Execute-Process -Path $exePath -Parameters $exeParams -WindowStyle 'Hidden'
    } else {
        Write-Log -Message "Executable not found at path: $exePath" -Severity 3
    }

#fallback to UninstallString if QuietUninstallString is missing
} elseif ($uninstallEntry.UninstallString) {
    Write-Log -Message "QuietUninstallString not found. Using UninstallString: $($uninstallEntry.UninstallString)" -Severity 2

    $parts = $uninstallEntry.UninstallString -split '\s+(?=(?:[^"]*"[^"]*")*[^"]*$)', 2
    $exePath = $parts[0].Trim('"')
    $exeParams = if ($parts.Count -eq 2) { "$($parts[1]) /quiet" } else { '/quiet' }

    if (Test-Path $exePath) {
        Execute-Process -Path $exePath -Parameters $exeParams -WindowStyle 'Hidden'
    } else {
        Write-Log -Message "Executable not found at path: $exePath" -Severity 3
    }

} else {
    Write-Log -Message "No uninstall string found for $targetDisplayName in 32-bit registry." -Severity 2
}

Uninstall UWP application – PSADT

$AppName = "DellInc.DellSupportAssistforPCs"

$AppPackage = Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*$AppName*" }
if ($AppPackage) {
    foreach ($pkg in $AppPackage) {
        Write-Log -Message "Removing AppxPackage for all users: $($pkg.PackageFullName)" -Severity 1
        Remove-AppxPackage -Package $pkg.PackageFullName -AllUsers -ErrorAction SilentlyContinue
    }
} else {
    Write-Log -Message "AppxPackage $AppName not found for any current users." -Severity 2
}

#remove provisioned package so it won’t install for new users
$ProvisionedApp = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*$AppName*" }
if ($ProvisionedApp) {
    foreach ($prov in $ProvisionedApp) {
        Write-Log -Message "Removing provisioned AppxPackage: $($prov.PackageName)" -Severity 1
        Remove-AppxProvisionedPackage -Online -PackageName $prov.PackageName -ErrorAction SilentlyContinue
    }
} else {
    Write-Log -Message "No provisioned package found for $AppName." -Severity 2
}

Detect UWP application

$AppName = "DellInc.DellSupportAssistforPCs"
$AppPackage = Get-AppxPackage -AllUsers | Where-Object { $_.Name -like "*$AppName*" }
$ProvisionedApp = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -like "*$AppName*" }

if ($AppPackage -or $ProvisionedApp) {
    Write-Output "Dell SupportAssist for PCs is installed."
    exit 0 
} else {
    Write-Output "Dell SupportAssist for PCs is not installed."
    exit 1
}