Skip to content

Instantly share code, notes, and snippets.

@msoler8785
Created December 19, 2023 14:12
Show Gist options
  • Save msoler8785/acc8eb1c03ca1fcc341189471efce390 to your computer and use it in GitHub Desktop.
Save msoler8785/acc8eb1c03ca1fcc341189471efce390 to your computer and use it in GitHub Desktop.
Install Winget on Windows Server
cd $env:USERPROFILE\Desktop
mkdir winget
cd winget
# Download appx bundles
if(-Not (Test-Path '.\microsoft.ui.xaml.2.7.3\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx'))
{
Invoke-WebRequest -Uri https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml/2.7.3 -OutFile .\microsoft.ui.xaml.2.7.3.zip
Expand-Archive .\microsoft.ui.xaml.2.7.3.zip
}
if(-Not (Test-Path '.\Microsoft.VCLibs.x64.14.00.Desktop.appx'))
{
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile .\Microsoft.VCLibs.x64.14.00.Desktop.appx
}
if(-Not (Test-Path '.\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'))
{
Invoke-WebRequest -Uri https://github.com/microsoft/winget-cli/releases/latest/download/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -OutFile .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
}
# Install NtObjectManager module
Install-Module NtObjectManager -Force
# Install AppxPackages
Add-AppxPackage .\microsoft.ui.xaml.2.7.3\tools\AppX\x64\Release\Microsoft.UI.Xaml.2.7.appx
Add-AppxPackage .\Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage .\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
# Create reparse point
$installationPath = (Get-AppxPackage Microsoft.DesktopAppInstaller).InstallLocation
Set-ExecutionAlias -Path "C:\Windows\System32\winget.exe" -PackageName "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe" -EntryPoint "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe!winget" -Target "$installationPath\winget.exe" -AppType Desktop -Version 3
explorer.exe "shell:appsFolder\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe!winget"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment