Do you want to uninstall EXE applications with PowerShell App Deployment Toolkit (PSADT)?

Then you should read this article, as i will learn you how to do exactly that.

If you are a frequent user of PowerShell App Deployment Toolkit (PSADT), you might know

the command Remove-MSIApplications , which can be used to remove MSI applications by searching the registry for their display name or GUID. However this will not work for EXE installed applications.

So how do i create a EXE uninstaller with PSADT?

I’m sure that it can be done in a lot of ways, but here i will show you two methods that i use myself.

The first one is very simple, and requires that you know where the uninstaller is, and that it is at the same location every time.

The second one, will search for the application in the registry and use the uninstall string as path to the uninstaller.

In this article i will use a real world example, the “Final Media Player”.

Simple uninstall

With the simple uninstall you simply use the Execute-Process command, the command for my use is the following:

Execute-Process -Path "$envProgramFiles\FinalMediaPlayer\unins000.exe" -Parameters '/SILENT'

As you can see this will require the uninstall file to be at the exact same location, and same filename on every computer.

I like to make my scripts dynamic, so lets take a look at the advanced method.

Advanced Uninstall

With the advanced uninstall, we grap a the application(s) using the Get-InstalledApplication command.

I add this to a list, because it can return multiple results, if it finds more then one match. So i want to make my script support that.

After the list, we use a ForEach to loop it through. Then we use the UninstallString from the Get-InstalledApplication to set our path for the uninstaller EXE.

As the last, i know my UninstallString includes a pair of “ in the name. PSADT do not like that, so i have added a -replace command, to remove it.

The final uninstall script looks like below.

Remember that you, would add the below script to the # <Perform Uninstallation tasks here> part of your Deploy-Application.ps1 script

# Get a list of applications matching "Final Media Player" $AppList = Get-InstalledApplication -Name 'Final Media Player' # Loop through the list, and performing the uninstall ForEach ($App in $AppList) { # Check if the uninstall string exists on the entry, if not we skip. If($App.UninstallString) { # Replacing " to nothing, as execute-process will fail if the path includes a " $UninstPath = $App.UninstallString -replace '"', '' # Check if the uninstall file exists, before we try to run it. If(Test-Path -Path $UninstPath) { # Writing status to log Write-log -Message "Found $($App.DisplayName) ($($App.DisplayVersion)) and valid uninstall string, trying to uninstall." # Running the actual uninstall. Execute-Process -Path $UninstPath -Parameters '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART' } } }

If you have any questions or feedback, then please leave a comment!

(For code comments, please use www.pastebin.com)

Download PSADT: http://psappdeploytoolkit.com/