Uninstall software remotely with WMIC

Here is a very useful command that will silently uninstall a remote application and reboot if required (I ran this on 2012 R2 servers).

Caution1: If you receive an error “Invalid node (discarded)” the command still lists software but it is from the local machine and not the remote server
Caution2: WMIC will not suppress a reboot. If the software requires a reboot to finish uninstalling the remote server will reboot without any prompts

To fix the WMIC Invalid node (discarded) error in case you run into it

Add rule to allow traffic to the RPC Dynamic Ports
Go to Computer Configuration > Policies > Windows Settings 
> Security Settings > Windows Firewall with Advanced Security 
> Windows Firewall with Advanced Security - LDAP 
> Inbound Rules.
Right-click and choose New Rule.
Choose Custom and click Next.
Choose All programs and click Next.
Select TCP as the Protocol type.
Select RPC Dynamic Ports as the Local Port and click Next.
Specify the IP address of the scan node on the 
remote IP addresses list or choose Any IP address and then 
click Next.
Select Allow the connection and click Next.

Enter WMIC

C:\>wmic
wmic:root\cli>

List software installed on the remote machine.

Stop if you receive “Invalid node (discarded)” error as the software listed is from the local server and not the remote server.

C:\>wmic
wmic:root\cli>/node:"server1" product get name
server1 - Invalid node (discarded).
Name
VMware Tools
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148

wmic:root\cli>

Uninstall software on the remote machine

The below command did not work, notice the “Invalid node (discarded) error”. Make sure the “Execute (\\DC\ROOT” is your remote server. DC in this case is the hostname of the server that I am running the command on. This would have uninstalled VMware tools on my local machine and restarted it.

wmic:root\cli>/node:"server1" product where name="VMware Tools" call uninstall
server1 - Invalid node (discarded).
Execute (\\DC\ROOT\CIMV2:Win32_Product.IdentifyingNumber=
"{4F3742E0-700E-431D-BF19-5B27ED98E8F1}",Name="VMware Tools",Version="10.0.0.
ninstall() (Y/N/?)?

I disabled the firewall on the remote server and now I was able to get the list of software. RPC ports need to be open for this command to work. Here is what the product list should look like. I no longer get Invalid node (discarded) error.

wmic:root\cli>/node:"server1" product get name
Name
Microsoft Application Error Reporting
Microsoft Access database engine 2010 (English)
Microsoft SQL Server System CLR Types
Microsoft Help Viewer 1.1
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4974
VMware Tools

Here is what the Uninstall command should look like. Notice the “Execute (\\SERVER1\ROOT….). This is where I want to uninstall the program “SERVER1” node. The server will reboot once I click Yes as VMware tools needs a reboot to properly uninstall.

wmic:root\cli>/node:"server1" product where name="VMware Tools" call uninstall
Execute (\\SERVER1\ROOT\CIMV2:Win32_Product.IdentifyingNumber="
{4F3742E0-700E-431D-BF19-5B27ED98E8F1}",Name="VMware Tools",
")->Uninstall() (Y/N/?)?

Useful WMIC queries

productget Description, InstallDate, Name, Vendor, Version

https://blogs.technet.microsoft.com/askperf/2012/02/17/useful-wmic-queries/

This entry was posted in Microsoft, Scripting and tagged , , . Bookmark the permalink.

One Response to Uninstall software remotely with WMIC

  1. Stefan says:

    also check the silent option: …..call uninstall /nointeractive

    But I haven’t found a FORCE option so far 🙁

Leave a Reply

Your email address will not be published. Required fields are marked *