How to uninstall software using WMI in PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

There are mainly 3 methods by which you can uninstall software using PowerShell.

  • WMI Method.

  • Using Package provider

  • Uninstallation String.

We will discuss here the WMI method to uninstall software.

WMI method

With WMI class Win32_Product you can retrieve the list of software uninstalled in your local or the remote systems. If you need specific software, you can filter by its name. For example,

Get-WmiObject Win32_Product -Filter "Name='Vmware tools'"

Or You can retrieve the name of the installed software using the Where-Object pipeline command.

Get-WmiObject Win32_Product | Where{$_.Name -eq "Vmware tools"}

Output

PS C:\Users\Administrator> Get-WmiObject Win32_Product | Where{$_.Name -eq
"Vmware tools"}
IdentifyingNumber : {D533345C-7F8D-4807-AE80-E06CE2045B0E}
Name              : VMware Tools
Vendor            : VMware, Inc.
Version           : 11.0.6.15940789
Caption           : VMware Tools

Below are the supported methods for this WMI object command.

Get-WmiObject Win32_Product -Filter "Name='Vmware tools'" | gm -MemberType Method
| Select Name, MemberType

Output

Name          MemberType
----          ----------
Configure       Method
Reinstall       Method
Uninstall       Method
Upgrade         Method

There is an Uninstall() method supported by this command. We can use this method to uninstall the software. For example,

$vtools = Get-WmiObject win32_product -Filter "Name='Vmware tools'"
$vtools.Uninstall()
raja
Published on 08-Aug-2020 07:41:59
Advertisements