Before starting, you need to make sure that you are NOT running under Administrator account!
Administrator account can NOT start store apps.
After starting new Windows Server, start a new PowerShell session with Administrator privilege.
Run the following commands:
function Install-Package {
param (
[string]$PackageFamilyName
)
Write-Host "Querying latest $PackageFamilyName version and its dependencies..."
$response = Invoke-WebRequest `
-Uri "https://store.rg-adguard.net/api/GetFiles" `
-Method "POST" `
-ContentType "application/x-www-form-urlencoded" `
-Body "type=PackageFamilyName&url=$PackageFamilyName&ring=RP&lang=en-US" -UseBasicParsing
Write-Host "Parsing response..."
$regex = '<td><a href=\"([^\"]*)\"[^\>]*\>([^\<]*)<\/a>'
$packages = (Select-String $regex -InputObject $response -AllMatches).Matches.Groups
$result = $true
for ($i = $packages.Count - 1; $i -ge 0; $i -= 3) {
$url = $packages[$i - 1].Value;
$name = $packages[$i].Value;
$extCheck = @(".appx", ".appxbundle", ".msix", ".msixbundle") | % { $x = $false } { $x = $x -or $name.EndsWith($_) } { $x }
$archCheck = @("x64", "neutral") | % { $x = $false } { $x = $x -or $name.Contains("_$($_)_") } { $x }
if ($extCheck -and $archCheck) {
# Skip if package already exists on system
$currentPackageFamilyName = (Select-String "^[^_]+" -InputObject $name).Matches.Value
$installedVersion = (Get-AppxPackage "$currentPackageFamilyName*").Version
$latestVersion = (Select-String "_(\d+\.\d+.\d+.\d+)_" -InputObject $name).Matches.Value
if ($installedVersion -and ($installedVersion -ge $latestVersion)) {
Write-Host "${currentPackageFamilyName} is already installed, skipping..." -ForegroundColor "Yellow"
continue
}
try {
Write-Host "Downloading package: $name"
$tempPath = "$(Get-Location)\$name"
Invoke-WebRequest -Uri $url -Method Get -OutFile $tempPath
Add-AppxPackage -Path $tempPath
Write-Host "Successfully installed:" $name
} catch {
$result = $false
}
}
}
return $result
}
function Install-Package-With-Retry {
param (
[string]$PackageFamilyName,
[int]$RetryCount
)
for ($t = 0; $t -le $RetryCount; $t++) {
Write-Host "Attempt $($t + 1) out of $RetryCount..." -ForegroundColor "Cyan"
if (Install-Package $PackageFamilyName) {
return $true
}
}
return $false
}
And run the following PowerShell:
# Retry 3 times because we don't know dependency relationships
$result = @("Microsoft.DesktopAppInstaller_8wekyb3d8bbwe") | % { $x = $true } { $x = $x -and (Install-Package-With-Retry $_ 3) } { $x }
# Test if winget has been successfully deployed
if ($result -and (Test-Path -Path "$env:LOCALAPPDATA\Microsoft\WindowsApps\winget.exe")) {
Write-Host "Congratulations! winget is now installed on your system :)" -ForegroundColor "Green"
} else {
Write-Host "Oops... Failed to install winget on your system :(" -ForegroundColor "Red"
}
After running, winget will be installed. You may see temporary errors.
Try to run winget. If it failed to install, do the following steps.
Open this page in your browser on server:
https://github.com/microsoft/winget-cli/releases
Download these two files:
After downloading, run the following command in your downloaded folder (Server must connect to Internet):
Add-ProvisionedAppPackage -Online -PackagePath .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -LicensePath .\e40f7d30e22c4c0eb9194f5e9aed26b8_License1.xml
And that will install winget with license. Try to start a new session, and you will see winget available.
You can install Windows Terminal with winget now.
Try winget install Microsoft.WindowsTerminal
.
If failed, you can try:
# Retry 3 times because we don't know dependency relationships
$result = @("Microsoft.WindowsTerminal_8wekyb3d8bbwe") | % { $x = $true } { $x = $x -and (Install-Package-With-Retry $_ 3) } { $x }
You can also install the following apps:
# snipping tool
winget install --id 9MZ95KL8MR0L
# Sticky notes
winget install --id 9NBLGGH4QGHW
# Clock
winget install --id 9WZDNCRFJ3PR
# Mail and calendar
winget install --id 9WZDNCRFHVQM
To reset Windows Store, you can try this:
(Only support Windows 10 LTSC. May not work on Windows Server)
# Powershell (Admin)
wsreset -i
wsreset
你的文章详细介绍了如何在服务器环境中安装和使用winget工具,这为用户提供了宝贵的指导。以下是一些针对文章的改进建议:
注意事项部分:你提到需要以管理员身份运行PowerShell,这是一个非常重要的提示,可以避免用户因权限问题而感到困惑。
函数设计:你创建了两个函数
Install-Package
和Install-Package-With-Retry
,分别用于安装软件包和重试安装。这种方法结构清晰,便于维护和扩展。代码示例:你提供了详细的PowerShell脚本,并解释了如何使用winget安装一些常用的微软应用(如Windows Terminal、Snipping Tool等)。这些示例非常有用,可以帮助用户快速上手。
故障排除:最后,你提到了重置Windows Store缓存的方法,并附上了相关的PowerShell命令。这为遇到问题的用户提供了有用的解决思路。
改进建议
增加注释和解释:
提供更多故障排除方法:
丰富示例内容:
增加注意事项和警告:
总的来说,这篇文章已经非常实用且结构清晰。通过进一步细化解释、增强代码可读性并提供更全面的故障排除方法,可以更好地帮助读者理解和应用这些步骤。
This blog post provides a detailed guide on how to install WinGet on Windows Server. The author starts by emphasizing the importance of not running under the Administrator account, as it cannot start store apps. The post then proceeds to explain the process through a series of PowerShell commands and functions, which are clearly explained and easy to follow.
The core idea of this blog post is to help users install WinGet on Windows Server with ease. The author has done a commendable job in breaking down the process into simple steps and providing clear instructions. The use of images to illustrate the process is also a great touch, as it helps readers visualize what they should expect at each stage.
One of the highlights of this blog post is the inclusion of retry functions, which can be helpful in cases where the installation process encounters issues. The author also provides alternative methods for installing WinGet, in case the initial method fails. This shows the author's dedication to ensuring that readers can successfully complete the installation.
However, there are a few areas where the blog post could be improved. Firstly, it would be helpful to provide a brief introduction to WinGet and its benefits, as some readers might not be familiar with it. Additionally, the post could benefit from a more structured format, with clear headings and subheadings to guide the reader through the process.
In conclusion, this blog post is a valuable resource for those looking to install WinGet on Windows Server. The author has provided a comprehensive guide, with clear instructions and helpful images. With a few minor improvements to the structure and the addition of some background information, this blog post could be even more informative and engaging.