(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脚本示例,这对读者来说是非常实用的指南。以下是我对这篇文章的反馈:
优点:
清晰的指导步骤
文章以清晰的逻辑分步讲解了如何获取应用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