Last active
January 24, 2024 13:30
-
-
Save gaoyifan/7c4d4bac07172141157472d0c2da6525 to your computer and use it in GitHub Desktop.
Install winget on Windows Server 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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