[英]PowerShell Core and AppX package management
I am using PowerShell 6.2 preview at the moment.我目前正在使用 PowerShell 6.2 预览版。 In my script I am trying to do stuff with Windows 10 apps.
在我的脚本中,我试图用 Windows 10 应用程序做一些事情。 To be able to use commands like
Get-AppxPackage
, I need to import Windows modules from previous PowerShell like so:为了能够使用像
Get-AppxPackage
这样的命令,我需要像这样从以前的 PowerShell 导入 Windows 模块:
Import-Module C:\Windows\system32\WindowsPowerShell\v1.0\Modules\Appx\Appx.psd1 -SkipEditionCheck
Import-Module C:\Windows\system32\WindowsPowerShell\v1.0\Modules\dism\dism.psd1 -SkipEditionCheck
Does PowerShell core has its own modules to work with this? PowerShell 核心是否有自己的模块来处理这个问题? I found
Get-Package
for example, but that does not give me anything.例如,我找到了
Get-Package
,但这并没有给我任何东西。
Since this is one of the top search results for PowerShell Core Get-AppxPackage , I'm going to take the information from the link provided in the comments and provide an answer, with example.由于这是PowerShell Core Get-AppxPackage的热门搜索结果之一,因此我将从评论中提供的链接中获取信息并提供答案,例如。
As LangsGalgEnRad pointed out in the comments, it's easiest just to do this from Windows PowerShell, but ultimately that's just-shy-of-deprecated at this point, with Microsoft stating that there are to be no more fixes or changes other than critical security issues.正如 LangsGalgEnRad 在评论中指出的那样,最简单的方法是从 Windows PowerShell 中执行此操作,但最终这在这一点上已被弃用,微软表示除了关键的安全问题外,没有更多的修复或更改. That said, it's still (afaik) universally available in Windows installations.
也就是说,它仍然(afaik)在 Windows 安装中普遍可用。
But for those of us who want to follow Microsoft's advice to use PowerShell Core, LangsGalgEnRad also points out in the comments the WindowsCompatibility
module from Microsoft.但是对于我们这些想要遵循 Microsoft 建议使用 PowerShell Core 的人来说,LangsGalgEnRad 还在评论中指出了 Microsoft 的
WindowsCompatibility
模块。 Reading the blog post, this seems a bit safer than importing a Windows module (eg AppX
) from PowerShell Core, since among other things ...阅读博客文章,这似乎比从 PowerShell Core 导入 Windows 模块(例如
AppX
)更安全,因为除其他外...
WindowsCompatibility
is very careful to not overwrite native PowerShell core commands.WindowsCompatibility
非常小心,不会覆盖本机 PowerShell 核心命令。
To install from PowerShell Gallery:从 PowerShell 库安装:
Install-Module WindowsCompatibility
Example usage for AppX
: AppX
示例用法:
Import-Module WindowsCompatibility
Import-WinModule AppX
Get-AppxPackage
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.