When setting up a lab environment for deploying Active Directory automation tools, we recognized the efficiency of using Winget to install software across multiple machines. However, Windows Server 2022 does not readily support Winget from Microsoft.
Our quest for solutions involved extensive research, with many references leading to more references. After navigating this information labyrinth, we decided to provide a quick guide for those looking to set up Winget on their Windows Server 2022 environment with minimal hassle.
Prerequisites
To follow this guide, you will need the following files:
Step 1: Get the Latest Winget CLI
Start by creating a new folder and navigating to it using PowerShell. Then, download Winget, UI.Xaml, and VCLibs into this folder:
# Set TLS 1.2 as the security protocol
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
# Download the latest Winget package files
$files = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/winget-cli/releases/latest" | Select-Object -ExpandProperty assets | Select-Object -ExpandProperty browser_download_url
foreach ($file in $files)
{
Invoke-WebRequest -Uri $file -UseBasicParsing -Outfile .\$(Split-Path -Path $file -Leaf)
}
Next, obtain the UI.Xaml NuGet package as a ZIP archive from nuget.org:
# Download UI.Xaml nupkg as a ZIP archive
Invoke-WebRequest -UseBasicParsing -Uri "https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3" -OutFile .\microsoft.ui.xaml.2.7.3.zip
Step 2: Prepare Files
Unzip the UI.Xaml archive to access the required files:
Expand-Archive .\microsoft.ui.xaml.2.7.3.zip -DestinationPath .\microsoft.ui.xaml.2.7.3
Step 3: Install Prerequisite Libraries and Winget
First, install the UI.Xaml package:
Add-AppxPackage -Path .\microsoft.ui.xaml.2.7.3\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx
Next, install VC.Libs:
Add-AppxPackage -Path .\Microsoft.VCLibs.x64.14.00.Desktop.appx
Finally, install Winget:
$licenseFile = Get-ChildItem -Path .\ -Filter *_License*.xml -File | Select-Object -ExpandProperty FullName
Add-AppxProvisionedPackage -Online -PackagePath .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -LicensePath $licenseFile
Congratulations, you have successfully installed Winget on Windows Server 2022.
Sincerely,
The Repass Cloud Team