Remove-MSIApplications for PSADT 4

Hi everyone,

I regularly use Remove-MSIAapplications in PSADT 3.8.4. I've built a suitable equivalent. I'm getting the message that the installation package cannot be opened. Nothing is being uninstalled, and I can still open it afterward. Does anyone have any ideas?

PSAppDeployToolkit.Extensions.psm1

function Uninstall-MSIByDisplayName {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]$DisplayName,

        [switch]$ExactMatch,

        [string]$AdditionalArguments = "/qn /norestart"
    )

    Write-ADTLogEntry -Message "Suche installierte MSI-Anwendung mit DisplayName: $DisplayName" -Severity 1

    try {
        if ($ExactMatch) {
            $Applications = Get-ADTApplication | Where-Object {
                $_.DisplayName -eq $DisplayName -and $_.WindowsInstaller -eq $true
            }
        }
        else {
            $Applications = Get-ADTApplication | Where-Object {
                $_.DisplayName -like "*$DisplayName*" -and $_.WindowsInstaller -eq $true
            }
        }

        if (!$Applications) {
            Write-ADTLogEntry -Message "Keine passende MSI-Installation gefunden für: $DisplayName" -Severity 2
            return
        }

        foreach ($App in $Applications) {
            Write-ADTLogEntry -Message "Gefundene MSI-Anwendung: $($App.DisplayName) - ProductCode: $($App.ProductCode)" -Severity 1
            
            if ($App.ProductCode) {
                Start-ADTProcess -FilePath "msiexec.exe" `
                                -ArgumentList "/x $($App.ProductCode) $AdditionalArguments" `
                                -WindowStyle Hidden `
								-WaitForMsiExec `
								-ErrorAction SilentlyContinue
                                
                Write-ADTLogEntry -Message "Deinstallation gestartet für: $($App.DisplayName)" -Severity 1
            }
            else {
                Write-ADTLogEntry -Message "Kein ProductCode gefunden für: $($App.DisplayName). Überspringe." -Severity 3
            }
        }
    }
    catch {
        Write-ADTLogEntry -Message "Fehler bei der MSI-Deinstallation: $_" -Severity 3
        throw
    }
}

Invoke-AppDeployToolkit.ps1
image

cu
bolle

Why not just use Uninstall-ADTApplication?

Something like this should work:
Uninstall-ADTApplication -name 'Zoom Workplace (64-bit)' -ApplicationType MSI

4 Likes

Thank you, that works perfectly, thank you.

cu

bolle

1 Like

We'd have to be crazy to remove such functionality out of the base product. Judging by some of your posts, I feel like you're just jumping in without reading any documentation, such as v4 Function Mapping · PSAppDeployToolkit.

I'd strongly recommend starting with that above link so you're not wasting your time writing code like the above for things the product already offers to you.