Important Note: When Win32_Product is queried, as here, it runs a consistency check on all Windows Installer applications, and performs automatic and silent repairs if needed. This may have undesired results on the target PC, and could make the already slow WMIC command even slower.
As an extension of my comments, in order to have a problem free base product list, I would advise that you create that list like this.
From a Command Prompt window:
(For /F Tokens^=6^ Delims^=^"^ EOL^= %G In ('%SystemRoot%\System32\wbem\WMIC.exe Product Get Name /Format:MOF') Do @Echo %G) 1>"%TEMP%\product-list.txt"
From a batch file:
@( For /F Tokens^=6^ Delims^=^"^ EOL^= %%G In ('
%SystemRoot%\System32\wbem\WMIC.exe Product Get Name /Format:MOF
') Do @Echo %%G) 1>"%TEMP%\product-list.txt"
Now to work on your question, using the output of the file produced above, and using the exact same methodology on the target PC's:
The following batch file should identify all Product
Name
s which do not match those in the base list:
@(Set LF=^
% 0x0A %
)
@For /F Delims^=^ EOL^= %%H In ('(
For /F Tokens^^^^^^^=6^^^^^^^ Delims^^^^^^^=^^^^^^^"^^^^^^^ EOL^^^^^^^= %%G In
('%SystemRoot%\System32\wbem\WMIC.exe Product Get Name /Format:MOF'^) Do @Echo
%%G^^^%%LF^^^%%Rem.^)^| %SystemRoot%\System32\findstr.exe
/XVLIG:"%TEMP%\product-list.txt"'
) Do @Echo %%H
@Pause
So once you're satisfied with the resulting output of the above script, just change Echo %%H
to %SystemRoot%\System32\wbem\WMIC.exe Product Where "Name='%%H'" Call Uninstall
Additional Note: You should be aware that there may be characters included in some of those name strings which do not render correctly in the codepage for your running batch file, or may not be understood in the WMIC.exe WHERE clause. Such things are outside of the scope of your question, and have not been catered for in the above answer.