Wednesday, March 27, 2019

Using wmic (Windows Management Interface Command) to remotely uninstall applications

I’ve recently been tasked to create a script that would remotely uninstall Adobe Flash on all desktops on the network and after not having any luck with PowerShell, I reverted to the wmic (Windows Management Interface Command) command I have used in the past.  While this isn’t the best way to guarantee the removal of the application in any environment it can be used in situations where you need a method that requires very little time.

The first step in the process is to obtain a list of computer names that you would like to remotely uninstall the application from and put it into a txt file with each name on a separate line.  If you intend on running it against all the computers in Active Directory then you can use the following PowerShell cmdlet to export the list in CSV format:

Get-ADComputer -Filter * -Property * | Select-Object Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Export-CSV AllWindows.csv -NoTypeInformation -Encoding UTF8

The above command would generate a CSV file as such:

You won’t need all the columns so simply copy the column with the computer names and paste it into a txt file then save it as computers.txt.

The command you’ll run with the reference to the computers.txt file will be the following:

wmic /failfast:on /node:@"computers.txt" product where "name like 'Adobe Flash%'" call uninstall /nointeractive

Note that the % sign is a wildcard and the following output will be displayed if the application is found and uninstalled on the remote computer:

No comments: