Here is a function that will uninstall an MSI installed application by the name of the app. You do not need to input the entire name either. For instance, say you are uninstalling all previous versions of Adobe Reader. Adobe Reader is always labeled Adobe Reader X, Adobe Reader XI, and so forth. This script allows you to do this without having to find out every version that is installed throughout a network and then enter an uninstaller line for each version. You just need to enter Adobe Reader as the application name and the desired switches. It will then search the name fields in the 32 and 64 bit uninstall registry keys to find the associated GUID. Finally, it will execute an msiexec.exe /x {GUID} to uninstall that version.
Update:
This is the third revision of the function that will uninstall an MSI by its application name. The last revision was an efficiency improvement. This revision adds the ability to uninstall all instances of an application. For instance, if several versions of Java 8 are installed, this function can uninstall all of them by just defining Java 8. The function covers both x86 and x64 based apps. The previous versions of this function could only uninstall one app at a time. This will uninstall all of them.
Here is a visual on the script uninstalling multiple versions of Java 8.
You can download the code from my GitHub site located here.
Update:
This is the third revision of the function that will uninstall an MSI by its application name. The last revision was an efficiency improvement. This revision adds the ability to uninstall all instances of an application. For instance, if several versions of Java 8 are installed, this function can uninstall all of them by just defining Java 8. The function covers both x86 and x64 based apps. The previous versions of this function could only uninstall one app at a time. This will uninstall all of them.
Here is a visual on the script uninstalling multiple versions of Java 8.
You can download the code from my GitHub site located here.
Nice! Here is a version that will work with Windows 10 and PackageManagement to uninstall msi, powershellget, or exe programs in a similar manner:
ReplyDeleteFunction Remove-InstalledApp ([string]$AppName) {
get-package $AppName -ErrorAction:SilentlyContinue | Foreach {
$app = $_
switch ($app.ProviderName) {
'msi' {
Write-Output "Uninstalling msi for $($app.Name)"
$app | Uninstall-Package
}
'PowerShellGet' {
Write-Output "Uninstalling PowerShellGet package for $($app.Name)"
$app | Uninstall-Package
}
'Programs' {
if ( $null -ne $app.metadata['UninstallString'] ) {
Write-Output "Found uninstall string for $($app.Name), calling it now..."
Invoke-Expression "& $($app.metadata['UninstallString'])"
}
}
Default {
Write-Output "Uncertain what we should do with package $($app.Name) (Provider = $($app.ProviderName))"
}
}
}
}
wmic product where (name like'java%%') call uninstall
ReplyDelete