Reputation: 3704
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?
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
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)
Upvotes: 1
Views: 2468
Reputation: 437548
Remove-AppxPackage
has an -AllUsers
switch only in recent versions of Windows (both desktop and server editions).
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.
Unfortunately, the Appx
module is not available in the PowerShell Gallery, so you cannot simply install the latest version with Install-Module
.
The need for doing this would imply that the docs for Windows Server 2016 are incorrect.
Upvotes: 1
Reputation: 49
The cmdlet, like many others also, would require you to elevate the PowerShell to have admin permissions if you want to affect other users.
Upvotes: 0