1

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)

Liam Kelly
  • 3,524
  • 1
  • 17
  • 41
  • My guess would be that, for some reason, `Remove-AppXPackage` cmdlet is using one of the other parameter sets that don't support `-AllUsers` (only one of three does). No clue why... You might want to double-check what's coming thru the pipeline on the problem machines. – Keith Miller Aug 04 '22 at 02:48
  • @KeithMiller, I don't think that's the problem, because you'd see a different error message in that case. However, it is conceivable for the help information and the actual cmdlet definition to be out of sync. – mklement0 Aug 04 '22 at 13:26
  • @LiamKelly: Are you aboe to check what parameters are available with tab-completion. – Keith Miller Aug 04 '22 at 13:57
  • @KeithMiller `-AllUsers` is not tab completing even when positionally it matches the `Get-Help` format (IE: `-Package $PKGNAME -AllUser`). Other Tab complete paramters still work in the same spot – Liam Kelly Aug 04 '22 at 14:04

2 Answers2

1

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.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • added an Update, is there any way to avoid scraping a more modern windows system? – Liam Kelly Aug 05 '22 at 17:11
  • @LiamKelly, there is a mysterious discrepancy in your version-info output: Your update suggests that you at least have an old version of the `AppX` module _loaded_ (imported), because the `Version` output of a `Get-Command` reports the command's _module's_ version. This module needn't be in the standard lookup locations (which `-ListAvailable` consults), but could have been imported from a nonstandard location, by explicit path, such as from a `$PROFILE` file. To rule this out, start a PowerShell session with `powershell.exe -noprofile` , or run `Remove-Module AppX -Force`. – mklement0 Aug 05 '22 at 18:20
  • To spell it out: `Get-Command Remove-AppxPackage` reporting `1.0` as the version implies that it was loaded from _version 1.0 of the `AppX` module_. – mklement0 Aug 05 '22 at 18:22
0

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

Tim
  • 39
  • 4