Every now and then, you may have the need to uninstall software, not just a single version but all versions of a certain product from your systems; e.g., QuickTime or Adobe Reader. Because these products are common components, you may have many different versions installed across your organization and because of these many different versions, you can’t just use a single command-line to uninstall them all.
The Solution to Uninstall Software En Masse
So how can we address this challenge? Create a script of course.
The uninstall software script I created (still VBScript to account for those systems still without PowerShell) does the following:
- Searches through the Uninstall key in the registry (both 32-bit and 64-bit on 64-bit OSes).
- Finds and loops through entries by DisplayName that contain a specified substring.
- Grabs the Uninstall string from the entry.
- Fixes up the uninstall string if needed.
- Replaces /I with /X.
- Adds /q if it’s not there already.
- Adds /norestart if it’s not there already.
- Runs the fixed up uninstall string to uninstall the product [optional].
- Outputs the number of matching products found to the console/stdout.
- Runs a hardware inventory [optional]
- Creates (or appends to) a log file (called Uninstall-Software.log) in the temp directory of the user running the script or the ConfigMgr logs folder if the ConfigMgr agent is detected.
The uninstall software script presented here takes one parameter (without which the script does almost nothing):
- /product:”<substring to search for>”
There are also two optional switches
- /uninstall — if specified actually runs the uninstall string
- /hwinv — if specified (and the ConfigMgr agent is installed on the system) runs a hardware inventory at the end
For testing purposes, simply don’t specify the uninstall switch. This will cause the log entries to be output to the console in addition to the log file.
If you need to modify the uninstall string fix-ups applied, simply edit the FixupUninstallString subroutine that starts on line 175.
The following are examples successfully used in a large production environment and deployed using a package and program in ConfigMgr CB (1602):
cscript.exe Uninstall-Software.vbs /product:”Adobe Reader” /uninstall
cscript.exe Uninstall-Software.vbs /product:”Adobe Acrobat Reader” /uninstall
cscript.exe Uninstall-Software.vbs /product:”Quicktime” /uninstall
Using in an Application
You can also use this script in an application by using the following guidelines:
- Create the application and a deployment type.
- Specifying one of the above command lines as the Uninstall command line in the deployment type.
- Use a noop for the install command line, something like the following:
cmd /c echo .
- Create a global condition that also runs the script except without the /uninstall switch.
- Set the detection method as this global condition and check for any value greater than 0.
- Deploy as an Uninstall optionally hiding it from the Software Center completely (as it would look awkward to the user if they see it there).
Using in Compliance Settings
It is also possible to use this script in a compliance item — you will have to increase the compliance item timeout however for it to successfully uninstall anything (https://blogs.msdn.microsoft.com/fei_xias_blog/2013/10/20/system-center-2012-configmgr-using-vbs-to-extend-the-dcm-script-execution-timeout-value/).
To do use the uninstall software script in this way, first modify lines 64, and 66-68. This is because we can’t pass parameters to scripts used in compliance items. Then use the script as both the detection and remediation script in the compliance item (each modified slightly differently per the notes in the script itself). Configure the setting check to check for a value equal to zero for the item to be compliant as anything else is non-compliant and that’s when we want the remediation script to kick in.