简体   繁体   English

Get-Help 显示 Remove-AppxPackage 的 `-AllUser` 参数,那么为什么 cmdlet 不接受它呢?

[英]Get-Help shows `-AllUser` parameter for Remove-AppxPackage, so why won't the cmdlet won't accept it?

I need a way to reliably remove all Appx Package from a system that start with a given string.我需要一种方法来可靠地从以给定字符串开头的系统中删除所有 Appx Package。 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:这基本上说AllUSers无效,但这与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?是否存在路径问题或其他方式为每个人删除 Appx package?

Update #1: Version info更新 #1:版本信息

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

Remove-AppxPackage has an -AllUsers switch only in recent versions of Windows (both desktop and server editions). Remove-AppxPackage仅在最新版本的 Windows(桌面版和服务器版)中具有-AllUsers开关。

  • 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 . 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.正如您稍后所说,您使用的是 Windows Server 2016,版本号表示最近的版本,所以-AllUsers应该可以工作。 For instance, on my recent Windows 10 release ( 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: For instance, on my recent Windows 10 release ( 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到您的1.0 ,这可以解释差异:

Your error message indeed implies that the cmdlet itself lacks an -AllUsers parameter - despite what the Get-Help may report (the information isn't guaranteed to be in sync).您的错误消息确实暗示 cmdlet 本身缺少-AllUsers参数 - 尽管Get-Help可能会报告什么(不能保证信息是同步的)。

  • 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; Get-Command -Syntax ,直接查阅命令的定义; 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).使用Get-Module -ListAvailable AppX查看您是否不小心安装了多个版本的AppX模块(过时的版本遮住了适合平台的版本),如果是,则删除除最新版本之外的所有版本(最高版本号)。

  • 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.否则,您可以尝试从最近的 Windows 10 / Windows Server 2019 或 Windows Server 2022 机器手动复制模块 - 但你必须看看它是否真的有效。

The cmdlet, like many others also, would require you to elevate the PowerShell to have admin permissions if you want to affect other users.与许多其他 cmdlet 一样,如果您想影响其他用户,则需要您提升 PowerShell 以获得管理员权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM