Remove WindowsPackage - PowerShell
Overview
Remove-WindowsPackage removes one or more Windows packages from a computer. Windows packages are typically installed using the Add-AppxPackage command or through the Microsoft Store.
Syntax
Remove-WindowsPackage [-Name] <String[]> [-AllUsers] [[-RegisteredOwner] <String>] [-ForceRemove] [-ForceRemoveAppSettings] [-SkipAppxRegistration] [<CommonParameters>]
Options/Flags
- -Name: Specifies the name(s) of the package(s) to remove. Wildcard characters can be used to match multiple packages.
- -AllUsers: Removes the package for all users on the computer. By default, the package is only removed for the current user.
- -RegisteredOwner: Specifies the registered owner of the package to remove. This is typically the user who installed the package.
- -ForceRemove: Removes the package even if it is in use by other processes. This can lead to unexpected behavior or data loss.
- -ForceRemoveAppSettings: Removes all application settings for the package. This can be useful if you are experiencing problems with the package.
- -SkipAppxRegistration: Skips the AppX registration process when removing the package. This can be useful if you are having problems removing the package.
Examples
Simple example:
Remove-WindowsPackage -Name Microsoft.WindowsCalculator
This command will remove the Microsoft Calculator package for the current user.
Complex example:
Get-WindowsPackage | Where { $_.PublisherName -eq "Contoso" } | Remove-WindowsPackage -AllUsers -ForceRemove
This command will remove all Windows packages published by Contoso for all users on the computer, even if the packages are in use by other processes.
Common Issues
- Error: The package cannot be removed because it is in use by another process.
Use the -ForceRemove flag to remove the package even if it is in use. This can lead to unexpected behavior or data loss.
- Error: The package cannot be removed because it is not registered with AppX.
Use the -SkipAppxRegistration flag to skip the AppX registration process when removing the package. This can be useful if you are having problems removing the package.
Integration
Remove-WindowsPackage can be used with other PowerShell commands to automate tasks. For example, the following script removes all Windows packages installed by a specific user:
$username = "johndoe"
Get-WindowsPackage | Where { $_.PublisherName -eq $username } | Remove-WindowsPackage -AllUsers
Related Commands
- Add-WindowsPackage: Installs a Windows package from a local file or the Microsoft Store.
- Get-WindowsPackage: Gets information about Windows packages installed on the computer.