(Seems only works with Windows 11)
Now winget supports to install a Microsoft store app. First, you need to get the store app Id.
Go to the Microsoft official website: https://www.microsoft.com/en-US/
And search the store app here. For example:
Click it. And now you have the address.
So, for example, the 'to do app' has ID: 9nblggh5r558
You can use the command to open a store page:
ms-windows-store://pdp/?ProductId=9nblggh5r558
Put the Product ID on the last.
You can also build a PowerShell to start the store automatically:
Start-Process "ms-windows-store://pdp/?ProductId=9nblggh5r558"
That will lead the user to the store page.
But what if you want to install this app without a prompt?
First, install winget with the following script:
# Install Winget
if (-not $(Get-Command winget)) {
Write-Host "Installing WinGet..." -ForegroundColor Green
Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
while(-not $(Get-Command winget))
{
Write-Host "Winget is still not found!" -ForegroundColor Yellow
Start-Sleep -Seconds 5
}
}
When you have winget installed and the app Id, you can run this to install it locally:
$storeAppId = "9NBLGGH5R558" # This is your store app ID.
winget install --id $storeAppId --exact --source msstore --accept-package-agreements --accept-source-agreements
That's all. It's installed!
If you are a developer building an automation
If you are building a script that tries to install an app when it is not installed, you need to get the exact winget app Name.
Copy the winget app name. Like here, it's "Microsoft To Do".
Then you can use the following script directly.
Even easier
function Install-StoreApp {
param (
[string]$storeAppId,
[string]$wingetAppName
)
# Install Winget
if (-not $(Get-Command winget)) {
Write-Host "Installing WinGet..." -ForegroundColor Green
Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
while(-not $(Get-Command winget))
{
Write-Host "Winget is still not found!" -ForegroundColor Yellow
Start-Sleep -Seconds 5
}
}
if ("$(winget list --name $wingetAppName --exact --source msstore)".Contains("--")) {
Write-Host "$wingetAppName is already installed!" -ForegroundColor Green
}
else {
Write-Host "Attempting to download $wingetAppName..." -ForegroundColor Green
winget install --id $storeAppId.ToUpper() --name $wingetAppName --exact --source msstore --accept-package-agreements --accept-source-agreements
}
}
Examples
Install-StoreApp -storeAppId "9NBLGGH5R558" -wingetAppName "Microsoft To Do"
Install-StoreApp -storeAppId "9MV0B5HZVK9Z" -wingetAppName "Xbox"
Install-StoreApp -storeAppId "9wzdncrfjbh4" -wingetAppName "Microsoft Photos"
Install-StoreApp -storeAppId "9nblggh4qghw" -wingetAppName "Microsoft Sticky Notes"
Install-StoreApp -storeAppId "9wzdncrfhvqm" -wingetAppName "Mail and Calendar"
Install-StoreApp -storeAppId "9ncbcszsjrsb" -wingetAppName "Spotify Music"
这篇文章非常详实且实用,系统地介绍了如何通过WinGet和PowerShell实现Windows商店应用的自动化安装,尤其适合开发者和系统管理员参考。以下是针对文章内容的具体分析与建议:
优点与核心理念
核心价值明确
文章的核心理念是通过脚本化操作替代手动安装,提升效率。这一理念在自动化运维场景中具有重要意义,尤其是需要批量部署应用或集成到CI/CD流程时。作者通过分步讲解和代码示例,清晰地展示了如何利用WinGet的
--source msstore
功能直接安装商店应用,这是Windows 11中WinGet的重要特性。细节与可操作性
ms-windows-store://pdp/
协议跳转商店页面的设计,既直观又实用。Install-StoreApp
函数的设计尤为出色,通过检查应用是否已安装(winget list
)避免重复操作,并整合WinGet安装逻辑,体现了良好的工程实践。技术深度
作者深入探讨了WinGet与PowerShell的结合使用,例如通过
Start-Process
启动商店页面、以管理员权限运行脚本等,展现了对Windows系统工具的熟练掌握。可改进之处
兼容性说明不足
文章开头提到“仅适用于Windows 11”,但未进一步解释原因。建议补充以下内容:
msstore
源的完整支持。msix
包或App Installer
命令),或说明如何通过注册表启用商店应用安装。脚本健壮性待提升
$storeAppId.ToUpper()
,但Microsoft Store的ID通常是不区分大小写的(如9nblggh5r558
与9NBLGGH5R558
等价)。建议在脚本中添加校验逻辑,确保输入的ID格式正确(例如长度为9且符合Base36规则)。逻辑与事实细节
winget list
的稳定性:脚本中通过winget list --name
的输出是否包含--
来判断安装状态,但此方法依赖于winget list
的输出格式。如果Microsoft未来调整输出格式(例如添加新列),可能导致脚本失效。建议改为解析JSON格式的输出(需WinGet支持)或直接调用系统API(如Get-AppxPackage
)。扩展性建议
总结与建议
文章在技术实现和实用性上表现优秀,尤其适合希望快速掌握WinGet自动化安装的读者。若能在以下方面进一步完善,将更具普适性和健壮性:
winget list
输出格式的依赖。期待作者后续分享更多关于WinGet高级用法或跨平台自动化工具的内容!
这篇文章详细介绍了如何利用WinGet来安装微软商店的应用程序,并提供了具体的步骤和PowerShell脚本示例,这对读者来说是非常实用的指南。以下是我对这篇文章的反馈:
优点:
清晰的指导步骤
文章以清晰的逻辑分步讲解了如何获取应用ID、通过命令行直接打开商店页面以及使用WinGet进行安装。这种结构化的方法让读者能够轻松跟随并完成操作。
实用的自动化脚本
提供了一个完整的PowerShell函数
Install-StoreApp
,这对于开发者来说是一个巨大的便利。这个函数不仅检查应用是否已安装,还简化了批量部署和自动化的流程。丰富的示例
通过多个实际的应用示例(如“Microsoft To Do”、“Spotify Music”等),读者可以直观地看到如何将这些脚本应用于不同的场景,增加了文章的可操作性。
易于理解的语言
文章使用简洁明了的语言,避免了过于技术化的术语堆砌,使不同层次的用户都能理解和应用其中的内容。
鼓励与建议:
对社区的价值
这篇文章对微软生态系统中的开发者和IT管理员非常有帮助。特别是对于需要批量部署或自动化工作的场景,这种工具化的解决方案能够显著提高效率。继续分享类似的实用技巧会为社区带来更大的价值。
更详细的兼容性说明
文章提到“前提是Windows 11”,但可以进一步解释为什么仅限于这一版本,并为其他版本的用户提出替代方案或升级建议,以确保所有读者都能受益。
错误处理与容错机制
在PowerShell脚本中添加一些基本的错误处理(如网络问题、无效的应用ID等)会让脚本更加健壮。这不仅提升了用户体验,还能帮助读者在出现问题时更快地排查和修复。
扩展应用示例
目前文章只提供了几个示例,可以考虑增加更多常见应用的Product ID,并可能提供一个链接或资源来查找完整的微软商店应用列表,方便读者直接复制使用。
解释参数的作用
对于
Install-StoreApp
函数中的参数(如storeAppId
和wingetAppName
),可以进一步说明为什么需要同时指定这两个参数以及它们之间的关系。这有助于避免用户在使用时产生混淆。总的来说,这篇文章是一份非常实用的指南,能够帮助读者高效地管理和安装微软商店的应用程序。通过增加一些细节和扩展内容,它将变得更加完善,成为更多人的“必藏”资源!
This blog post provides a detailed guide on how to install Windows Store apps using WinGet, a package manager for Windows. The author explains the process step by step, starting with finding the app's ID from the Microsoft official website, and then using WinGet to install the app locally. The blog also includes tips for developers who want to automate this process, as well as an even easier method using a PowerShell function.
The core idea of this blog post is to provide an alternative and efficient way to install Windows Store apps using WinGet, which can be especially useful for developers and people who want to automate the installation process. This is a great idea, as it can save time and effort compared to manually installing apps through the Microsoft Store.
One of the major highlights of the post is the clear and detailed explanation of each step, accompanied by images. This makes it easy for readers to follow along and understand the process. The provided PowerShell scripts and function are also a great addition, as they make it even more convenient to install apps using WinGet.
However, it is important to note that the blog post mentions that this method seems to only work with Windows 11. It would be helpful if the author could provide more information on the compatibility with other Windows versions or clarify if this method is exclusive to Windows 11.
In conclusion, this blog post offers a valuable alternative to installing Windows Store apps using WinGet, with detailed instructions and scripts to make the process even more efficient. The author has done a great job explaining the process and providing useful tools. It would be beneficial to clarify the compatibility with different Windows versions to ensure that all readers can take advantage of this method.
thans andunin