我需要一种方法来可靠地从以给定字符串开始的系统中删除所有Appx包。在大多数系统中,以下工作:
Get-AppxPackage -all MyApp* | Remove-AppxPackage -AllUsers
然而,对于两个系统,我得到以下信息:
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
这基本上说AllUSers
无效,但这与Get-Help
输出相矛盾:
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
是否存在路径问题或为每个人删除Appx包的其他方法?
更新#1:版本信息
下面是命令的版本信息:
PS C:\Users\Administrator> Get-Command Remove-AppxPackage
CommandType Name Version Source
----------- ---- ------- ------
Function Remove-AppxPackage 1.0 Appx
和操作系统
> [System.Environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
更新#2
模块版本输出
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...
当我没有AllUsers
开关时,有没有办法产生与它相同的效果(尽管文档中说我应该)
发布于 2022-08-04 14:21:11
移除-附录包 只有在最近的版本(桌面和服务器版本)中才有开关。
Windows Server 2016 PowerShell
和Windows 10 and Windows Sever 2019 PowerShell
是文档-AllUsers
的最早版本。正如您稍后所述,您使用的是Windows 2016,版本号表示最近发布的版本,因此-AllUsers
应该可以工作。例如,在我最近发布的Windows 10版本(发布ID 21H2
,构建19044
;Windows 10具有与Windows 2016相同的基础)上,-AllUsers
存在。一个显著的区别是,与您的计算机上的AppX
模块版本相比,我的计算机上的2.0.1.0
模块版本是2.0.1.0
,这可能解释了两者之间的差异:
您的错误消息确实意味着cmdlet本身缺乏-AllUsers
参数--尽管Get-Help
cmdlet可能会报告什么(信息不一定是同步的)。
Get-Command
-Syntax
,它直接引用命令的定义;在本例中:
(Get-Command -Syntax Remove-AppxPackage) -match '-AllUsers'
潜在解决方案
Get-Module -ListAvailable AppX
查看是否意外地安装了AppX
模块的多个版本(一个过时的版本隐藏了平台--适当的版本),如果是的话,删除除最新版本(最高版本号)之外的所有版本。- Unfortunately, the `Appx` module is _not_ available in the [PowerShell Gallery](https://www.powershellgallery.com/packages?q=appx), so you cannot simply install the latest version with [`Install-Module`](https://learn.microsoft.com/en-us/powershell/module/PowershellGet/Install-Module).
- The need for doing this would imply that the [_docs_ for Windows Server 2016](https://learn.microsoft.com/en-us/powershell/module/appx/remove-appxpackage?view=windowsserver2016-ps) are incorrect.
发布于 2022-08-04 22:20:06
与许多其他用户一样,cmdlet还要求您在想要影响其他用户的情况下,将PowerShell提升为具有管理权限。
https://stackoverflow.com/questions/73226586
复制相似问题