- Block notifications in Chrome, Edge, and Firefox - Tue, Nov 29 2022
- VMware vSphere 8: Editions, licensing, and pricing - Mon, Nov 21 2022
- Automate file downloads with Windows FTP or curl - Wed, Nov 16 2022
Even when uninstalling Windows components, there is an unnecessary variety of options, such as Remove-WindowsCapability, Remove-WindowsFeature, and Disable-WindowsOptionalFeature. In addition, there is Remove-WindowsPackage from the DISM module.
CLI options for uninstalling applications ^
The command line tools for uninstalling programs are similarly inconsistent. A few years ago, Microsoft introduced PowerShell Package Management, which is primarily for adding and removing PowerShell modules. However, it is also suitable for uninstalling Win32 programs.
Then, in 2020, the package manager winget was added. A year later, it offered the ability to remove programs. However, it still does not have a PowerShell interface, and thus is limited in its options when automating package management.
In addition, separate cmdlets exist for Store and UWP apps with Remove-AppxProvisionedPackage and Remove-AppxPackage.
Finally, it is possible to uninstall applications using WMI. This is the only mechanism mentioned here that can perform this task remotely.
Uninstalling programs via WMI ^
The class Win32_Product is responsible for this. With its help, you can first view the installed software:
Get-CimInstance -Class Win32_Product -ComputerName <Remote-PC> | -Format-List
Once you have viewed the program in question, you can further narrow the list:
Get-CimInstance -Class Win32_Product -ComputerName <Remote-PC> | where name -like " PowerShell*"
If you send the output of this command through a pipe to Get-Member, you will not find an uninstall method. To get it, you have to use the older Get-WMIObject instead:
$app = Get-WmiObject -Class Win32_Product -ComputerName <Remote-PC> | where name -Like "PowerShell*"
In our example, this call captures an outdated version of PowerShell 7 and assigns the result to the $app variable.
Then, uninstall the program with
In general, this method works quite reliably and uninstalls applications remotely. However, it is hampered by the fact that the installed programs usually cannot be displayed completely via WMI.
Tools like 7-zip don't appear at all, and others appear only with a GUID, so you don't know what the entry stands for. In this case, you can switch to package management, which only works locally.
Remove programs with uninstall-package ^
To list the installed programs, use the Get-Package cmdlet. However, this also shows standalone updates (msu) or modules installed with PowerShellGet. Therefore, you can filter the output for traditional Win32 applications as follows:
Get-Package -ProviderName Programs -IncludeWindowsInstaller
Once you have found the program in question, specify it using the Name parameter and pass it to Uninstall-Package:
Get-Package -Name "7-zip*" | Uninstall-Package
Get-Package also enables filtering programs by their version number and uninstalling only certain versions (for example, "RequiredVersion") or all versions ("AllVersions").
Microsoft offers quite a jumble of program removal techniques. None of them covers the full range of required features. Either they are limited to certain types of programs or are incapable of removing programs remotely.
Subscribe to 4sysops newsletter!
The latter can be done via WMI, although you can't use the new CIM cmdlets for that. If you only get an incomplete list of installed software this way, then you can use the cmdlets from the PackageManagement package—but only locally.