Skip to content

Instantly share code, notes, and snippets.

@garysassano
Last active June 10, 2025 19:55
Show Gist options
  • Save garysassano/0224e58bbb2403420674a4bf73a11b59 to your computer and use it in GitHub Desktop.
Save garysassano/0224e58bbb2403420674a4bf73a11b59 to your computer and use it in GitHub Desktop.
# Check admin privileges
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Host "Run as Administrator required." -ForegroundColor Red
exit 1
}
Write-Host "Installing WinGet on new system..." -ForegroundColor Green
try {
# Create temp directory
$tempDir = "$env:TEMP\WinGetInstall"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
# Install VC++ Libraries
Write-Host "Installing VC++ Libraries..." -ForegroundColor Yellow
$vcFile = "$tempDir\vclibs.appx"
Invoke-WebRequest -Uri "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" -OutFile $vcFile -UseBasicParsing
Add-AppxProvisionedPackage -Online -PackagePath $vcFile -SkipLicense
# Install UI XAML x64 (get latest with .appx files)
Write-Host "Installing UI XAML..." -ForegroundColor Yellow
$xamlFile = "$tempDir\xaml.appx"
# Get latest release with .appx files using GitHub API
$releases = (Invoke-WebRequest -Uri "https://api.github.com/repos/microsoft/microsoft-ui-xaml/releases" -UseBasicParsing | ConvertFrom-Json)
$latestWithAppx = $releases | Where-Object { -not $_.draft -and -not $_.prerelease -and ($_.assets | Where-Object { $_.name -like "*.appx" }) } | Select-Object -First 1
$xamlUrl = ($latestWithAppx.assets | Where-Object { $_.name -match "Microsoft\.UI\.Xaml\.[^.]+\.x64\.appx" }).browser_download_url
Invoke-WebRequest -Uri $xamlUrl -OutFile $xamlFile -UseBasicParsing
Add-AppxProvisionedPackage -Online -PackagePath $xamlFile -SkipLicense
# Install WinGet
Write-Host "Installing WinGet..." -ForegroundColor Yellow
$wingetFile = "$tempDir\winget.msixbundle"
Invoke-WebRequest -Uri "https://aka.ms/getwinget" -OutFile $wingetFile -UseBasicParsing
Add-AppxProvisionedPackage -Online -PackagePath $wingetFile -SkipLicense
# Clean up
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Write-Host "✓ Installation complete!" -ForegroundColor Green
Write-Host "Restart PowerShell to use WinGet." -ForegroundColor Cyan
} catch {
Write-Host "Installation failed: $($_.Exception.Message)" -ForegroundColor Red
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment