I need a way to reliably remove all Appx Package from a system that start with a given string. On most systems the following works:
Get-AppxPackage -all MyApp* | Remove-AppxPackage -AllUsers
However for two systems I get the following:
PS C:\Users\Administrator> Get-AppxPackage -all CDI* | Remove-AppxPackage -AllUsers
Remove-AppxPackage : A parameter cannot be found that matches parameter name 'AllUsers'.
At line:1 char:48
+ Get-AppxPackage -all CDI* | Remove-AppxPackage -AllUsers
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-AppxPackage], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand
This basically says AllUSers is invalid, but this contradicts the Get-Help output:
Get-Help Remove-AppxPackage -Parameter AllUsers
-AllUsers [<SwitchParameter>]
{{Fill AllUsers Description}}
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
Is there a Path issue or another way to remove the Appx package for everyone?
Update #1: Version info
Here is the version info for the command:
PS C:\Users\Administrator> Get-Command Remove-AppxPackage
CommandType Name Version Source
----------- ---- ------- ------
Function Remove-AppxPackage 1.0 Appx
And the OS
> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
Update #2
Module version output
PS > Get-Module -ListAvailable Appx
Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0.0.0 Appx {Add-AppxPackage, Get-AppxPackage, Get-AppxPackageManifest...
Is there any way to produce the same effect as the AllUsers Switch when i don't have it (even though the documentation says i should)
Remove-AppxPackagehas an-AllUsersswitch only in recent versions of Windows (both desktop and server editions).Windows Server 2016 PowerShellandWindows 10 and Windows Sever 2019 PowerShellare the earliest versions that document-AllUsers.As you've stated later, you're using Windows Server 2016, and the version number indicates a recent release, so
-AllUsersshould work. For instance, on my recent Windows 10 release (release ID21H2, build19044; Windows 10 has the same foundation as Windows Server 2016),-AllUsersis present. A notable difference is that theAppXmodule version is2.0.1.0on my machine, compared to1.0on yours, which may explain the difference:Your error message indeed implies that the cmdlet itself lacks an
-AllUsersparameter - despite what theGet-Helpcmdlet may report (the information isn't guaranteed to be in sync).If you want to know whether a given command truly supports a given parameter, use
Get-Command-Syntax, which directly consults the command's definition; in this case:(Get-Command -Syntax Remove-AppxPackage) -match '-AllUsers'A simpler alternative is to try to tab-complete the parameter name: if nothing happens, the parameter doesn't exist.
Potential solutions:
Use
Get-Module -ListAvailable AppXto see if you accidentally have multiple versions of theAppXmodule installed (with an obsolete one shadowing the platform-appropriate one), and if so, remove all but the most recent one (highest version number).Otherwise, you can try to manually copy the module from a recent Windows 10 / Windows Server 2019 or a Windows Server 2022 machine - but you'll have to see if that actually works.
Unfortunately, the
Appxmodule is not available in the PowerShell Gallery, so you cannot simply install the latest version withInstall-Module.The need for doing this would imply that the docs for Windows Server 2016 are incorrect.