sccm 2012

Uninstalling a Program If It is installed Task Sequence and WMI Explorer

Hi Everyone,

Yesterday one of my colleague asked me to create a task sequence which first checks if a specific version of a program installed on the client machine and if it is installed, it will first uninstalls it and then it will install the latest version of the program. Let’s see how I did it.

First I need to create an uninstall package and the command I need to use something like this.

msiexec.exe /x {your-product-code-guid}

To obtain the product code GUID, you can run this command and on a client machine on which that specific version of the program installed.

get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name, LocalPackage -AutoSize

This the GUID I will use


Create a batch file and add the below uninstall command in it.

msiexec /x {BBAA7ABC-1B9F-410C-BB9E-D55285AAB9F0} /qn /norestart

Create the Uninstall Package:

We can now create the uninstall package, browse the folder path in which your batch file resides

Choose Standard program

Make sure you enter the name of the batch file in command line box and complete the rest of the wizard. Distribute this package to DPs.

Create the Application:

Let’s create the application we will install at the final step of our task sequence.

complete the wizard and distribute the Application to DPs.

Create the Task Sequnce:

Now lets create a Custom Task Sequence. Right click and Edit the TS.

Add>Software>Install Package

This task step (Uninstalling) will be executed if the specified software is installed, if not the step will be skipped.

Name this step as Uninstalling X Program, click on Options Tab

Add Condition> If Statement > All Conditions

Add Condition> Query WMI > WMI Namespace root\cimv2

WQL Query: select * from win32_product where name like “%displaylink%” and version = “8.3.2010.0”

It is important that you select the correct namespace and class when you are generating your WQL Query. You can use WMI Explorer Tool to test your WQL queries. On a client computer, run WMI Explorer Tool> select namespace and class and type in the query you wanna test and hit execute. If namespace and class and the query you run is valid, you will see its result like the picture below.Otherwise it will give error message stating “invalid class”.

Now add a step to install the application

Add>Software>Install > Hit the Star Icon and add the application you want to install

In Conclusion, task sequence will check if the specifed software is installed or not. If it is not installled it will continue to second step and install the application. If software is found, it will first uninstall it, and the install the application.

Post Comment