In this article, we’ll look at how to uninstall software on a local or remote Windows computer using PowerShell. Quite often, the system administrator uses scripts to uninstall Windows applications. You can use several approaches to remove programs from the command prompt or PowerShell scripts.
Using WMI to Uninstall Programs in Windows
The most common way to remove installed programs on Windows is to use commands that refer to the WMI namespace. For example, you can query the WMI namespace and get a list of installed programs with the wmic command.
wmic product get name,version
To silently uninstall an application from this list, you may use the command below:
wmic product where name="VMware vCenter Converter Standalone" call uninstall /nointeractive
The command calls an app uninstallation WMI method through the Windows Installer.
Executing (\\COMPName\ROOT\CIMV2:Win32_Product.IdentifyingNumber="{PROGRAM_GUID}",Name="VMware vCenter Converter Standalone",Version="6.2.0.8466193")->Uninstall()
If the program is successfully uninstalled, it will return:
Method execution successful. Out Parameters: instance of __PARAMETERS { ReturnValue = 0; };
Here are similar PowerShell commands to display and uninstall apps via WMI:
Get-WmiObject Win32_Product | ft name,version,vendor,packagename
(Get-WmiObject Win32_Product -Filter "Name = 'XXX'").Uninstall()
In order to remove a program on a remote computer, add the -ComputerName option. For example, to uninstall Microsoft Office on a remote computer, run the command below:
$apps = Get-WmiObject -Class Win32_Product -ComputerName wkmn-man23 |where name -Like "Office 16 Click-to-Run*"
$apps.uninstall()
However, this method of removing applications is not universal enough for all possible cases. If you compare the list of programs returned via the WMI namespace and the list of apps in the Windows Control Panel/ Apps & features list in Settings (use the MS-Settings quick access command: ms-settings:appsfeatures
), you will see that they differ. The wmi command only displayed a list of programs installed through the Windows Installer. The list doesn’t include most user apps (browsers, for example).
In addition, UWP programs from the Microsoft Store, and PowerShell modules (via PowerShellGet) are not displayed.
Uninstall Apps on Remote Computer with PowerShell Package Manager Module
In modern Windows 10/11 builds and Windows Server 2022/2019/2016, you can use the built-in PowerShell Package Management cmdlets to install or uninstall apps. Originally, the module was used to install/uninstall PowerShell modules. However, you may use it to uninstall Win32 programs, MSU updates, and apps installed using MSI installers as well.
To display a complete list of installed apps on a local computer, run the command below:
Get-Package
The command returns several classes of programs installed through the different providers (ProviderName). You can display a list of providers on a computer as follows:
Get-PackageProvider
- Programs
- Msi
- Msu
- PowerShellGet
- NuGet
To show a list of programs installed via a specific provider, run this command:
Get-Package -ProviderName Programs -IncludeWindowsInstaller
Use the Uninstall-Package cmdlet to remove the program:
Get-Package -Name "Notepad++*" | Uninstall-Package
You can remove the installed PowerShell module. For example, to uninstall all VMware.PowerCLI modules:
Get-Package -ProviderName PowerShellGet -Name "VMware.*" | Uninstall-Package
To uninstall a program on a remote computer, use the Invoke-Command cmdlet:
Invoke-Command -ComputerName mun-dc01 -ScriptBlock { Get-Package -Name "Notepad++*" | Uninstall-Package}
You can use this module to uninstall Win32 apps and PS modules only. To remove UWP apps from Microsoft Store, use the Remove-AppxPackage
or Remove-AppxProvisionedPackage
PowerShell cmdlets (see an example in this article).
How to Uninstall App with WinGet Command?
You can use the new WinGet package manager (it is built into Windows 10 and 11) to install and remove programs on Windows. To get a list of programs on your computer, run:
winget list
The command returns a list of programs including those installed using other methods than winget and a list of UWP (APPX) apps.
To remove apps installed via WinGet, run the command below:
winget uninstall --name 7zip.7zip
To uninstall an MSI app in Windows, specify its GUID:
winget uninstall --id "{332C1E78-1D2F-4A64-B718-68095DC6254B}"
To uninstall a UWP app:
winget uninstall --id "Microsoft.ZuneVideo_8wekyb3d8bbwe"
However, winget doesn’t allow you to uninstall programs on a remote computer. To execute winget command on a remote computer, use the PowerShell Remoting features (Invoke-Command and Enter-PSSession cmdlets). For example:
Invoke-Command -ComputerName wkmn-man231 -ScriptBlock {winget uninstall --name 7zip.7zip}
You can use the PowerShell scripts shown here to remotely uninstall programs or run them on domain computers using SCCM or GPO logon scripts.
1 comment
awsome,but still i got some problem when i try uninstall some application on my pc.when i try to use
Get-Package -Name “**” | Uninstall-Package,it stuck there for like ten more mins.took that so much time then i shut it down.