Home > Mobile >  Get-Help shows `-AllUser` parameter for Remove-AppxPackage, so why won't the cmdlet won't
Get-Help shows `-AllUser` parameter for Remove-AppxPackage, so why won't the cmdlet won't

Time:08-05

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

CodePudding user response:

The cmdlet, like many others also, would require you to elevate the PowerShell to have admin permissions if you want to affect other users.

CodePudding user response:

Remove-AppxPackage has an -AllUsers switch only in recent versions of Windows (both desktop and server editions).

  • On the linked page, browsing the version-specific doc pages (via the dropdown list of versions above the list of topics on the left) shows that Windows Server 2016 PowerShell and Windows 10 and Windows Sever 2019 PowerShell are 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 -AllUsers should work. For instance, on my recent Windows 10 release (release ID 21H2, build 19044; Windows 10 has the same foundation as Windows Server 2016), -AllUsers is present. A notable difference is that the AppX module version is 2.0.1.0 on my machine, compared to 1.0 on yours, which may explain the difference:

Your error message indeed implies that the cmdlet itself lacks an -AllUsers parameter - despite what the Get-Help cmdlet 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 AppX to see if you accidentally have multiple versions of the AppX module 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.

  • Related