Uninstalling a package with WinGet
What
wingetWinGet is a command line tool to manage applications on the Windows 10 and 11 platform.
When/Why
After we initially install any package, we most likely will have reason to uninstall it at some point...and we can use this very practically in a pre or post-uninstall script within a payload/fileset.
How
The process for removing a package is very similar to our installation and upgrade code, and equally simple. We'll use the winget "uninstall" commandWinGet to remove a previously installed package. You'llClicking findthe MicrosoftFileset documentationand then Properties in the toolbar will bring you to the settings which will control if a WinGet application is removed by breaking the Association or Deployment.
Below is the properties dialog for the Fileset.
Things to consider on the updateproperties commanddialog:
- Name - Is it the
uninstallnamecommandyou expected? - URL - The publisher of the software. Go there and confirm it is
shownwhatinyouactionexpected. - Uninstall when made passive - Do you want it to uninstall when the Association or Deployment is removed? Checking this box will make it so that if the Association or Deployment is removed in the
last line below:# Getfuture, thepathsoftware should silently uninstall.
Keep in mind that some software does not silently uninstall so you should always test if you are going to winget.exeenable $wingetthis =option. (Get-ChildItemThe -Pathuninstall "C:\Programfunctionality Files\WindowsApps\"is -Filterup "winget.exe" -Recurse | Sort-Object -Property LastWriteTime | Select-Object -Last 1).FullName
# Getto the directorysoftware that winget.exe is inside of
$wingetdir = Split-Path -Path $winget -Parent
# we change directoryvendor to thisimplement locale so we can run the winget command without the full path
cd $wingetdir
# uninstall doesn't have agreements, so we can exclude those options
# see special note on the meaning of "silent"
.\winget.exe uninstall --exact --id Mozilla.Firefox --silent
Utilization of the winget list command may also be very helpful in finding out which packages are currently installed. You can find details on that command here.
"Silent" doesn't necessarily mean silent in all cases. This winget process just uses normal install and uninstall options from third parties, but in an easy-to-use package. properly. What our testing has foundfound, thoughthough, is that the uninstall will only be "silent" if the 3rd party includes a QuietUninstallString in HKLM/Software/Microsoft/Windows/CurrentVersion/Uninstall. In ourthe case above,of Firefox, Mozilla provides no such string...they only provide an UninstallString, which does prompt. So, "silent" in this case is not silent. As always, testing of these items before production rollout is always recommended.
Digging Deeper
You may be asking yourself can I make the uninstall silent if it isn't? Yes, probably. In the case of Firefox for instance, the uninstall string calls an executable called helper.exe. That executableexecutable, though, when run with a /S flag, will actually uninstall the application silently. So the command to do this could be placeplaced into eitheran the pre or post-uninstallActivation script on thea separate Fileset to accomplish it instead of using the wingetWinGet command.command if you find you need to solve for this.