Skip to content

Instantly share code, notes, and snippets.

@gaoyifan
Last active January 24, 2024 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gaoyifan/7c4d4bac07172141157472d0c2da6525 to your computer and use it in GitHub Desktop.
Save gaoyifan/7c4d4bac07172141157472d0c2da6525 to your computer and use it in GitHub Desktop.
Install winget on Windows Server 2022
# from https://gist.github.com/likamrat/cae833a6e5b3461709f14c093c21c293?permalink_comment_id=4634351#gistcomment-4634351
# Install Chocolately Package Manager
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
$env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User"))
# Install WinGet from Chocolatey
choco install winget
choco install winget.powershell
# Fix Permissions
TAKEOWN /F "C:\Program Files\WindowsApps" /R /A /D Y
ICACLS "C:\Program Files\WindowsApps" /grant Administrators:F /T
# Add Environment Path
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
if ($ResolveWingetPath) {
$WingetPath = $ResolveWingetPath[-1].Path
}
$ENV:PATH += ";$WingetPath"
$SystemEnvPath = [System.Environment]::GetEnvironmentVariable('PATH', [System.EnvironmentVariableTarget]::Machine)
$SystemEnvPath += ";$WingetPath;"
setx /M PATH "$SystemEnvPath"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment