Skip to content

Instantly share code, notes, and snippets.

@fcenobi
Last active November 9, 2022 23:56
Show Gist options
  • Save fcenobi/502a16e3dc7f97b2b00afd29f87a1025 to your computer and use it in GitHub Desktop.
Save fcenobi/502a16e3dc7f97b2b00afd29f87a1025 to your computer and use it in GitHub Desktop.
install winget on windows 10 from powershell
function script-from-github ($weburl) {
$ScriptFromGitHub = Invoke-WebRequest $weburl -UseBasicParsing
Invoke-Expression $($ScriptFromGitHub.Content)
}
$weburl = https://gist.githubusercontent.com/fcenobi/502a16e3dc7f97b2b00afd29f87a1025/raw/cc599e096c29a18b398a82c5b3258175bdee0aa8/install-winget.ps1
script-from-github $weburl
taskkill /F /IM explorer.exe
explorer.exe
Set-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' -Name 'LongPathsEnabled' -Value 1
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop bucket add extras
scoop bucket add java
scoop bucket add nirsoft-alternative https://github.com/MCOfficer/scoop-nirsoft.git
scoop bucket add wsl https://git.irs.sh/KNOXDEV/wsl
scoop bucket add php
scoop bucket add alias-additions https://github.com/snaphat/alias-additions.git
scoop bucket add nirsoft 'https://github.com/Ash258/Scoop-NirSoft.git'
scoop install alias-additions
scoop install 7zip
scoop install innounp
scoop install wixtoolset
$repo = "microsoft/winget-cli"
$filenamePattern = "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.appxbundle"
$pathExtract = ""
$innerDirectory = $true
$preRelease = $true
function Test-Elevated {
$userID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$userPrincipal = New-Object System.Security.Principal.WindowsPrincipal($userID)
return $userPrincipal.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (Test-Elevated) {
if ($preRelease) { $releasesUri = "https://api.github.com/repos/$repo/releases" } else { $releasesUri = "https://api.github.com/repos/$repo/releases/latest" }
$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri)[0].assets | Where-Object name -like $filenamePattern).browser_download_url
$pathZip = Join-Path -Path $([System.IO.Path]::GetTempPath()) -ChildPath $(Split-Path -Path $downloadUri -Leaf)
Invoke-WebRequest -Uri $downloadUri -Out $pathZip
Add-AppProvisionedPackage -Online -SkipLicense -PackagePath $pathZip
}
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://gist.github.com/fcenobi/502a16e3dc7f97b2b00afd29f87a1025/raw'))"
# Create a file named "winget.txt" in the same directory as this script.
# Write exact names for packages on each line.
# Ex: filename: winget.txt
# Microsoft.Edge
# Google.Chrome
Write-Host "Checking winget..."
Try{
# Check if winget is already installed
$er = (invoke-expression "winget -v") 2>&1
if ($lastexitcode) {throw $er}
Write-Host "winget is already installed."
}
Catch{
# winget is not installed. Install it from the Github release
Write-Host "winget is not found, installing it right now."
$repo = "microsoft/winget-cli"
$releases = "https://api.github.com/repos/$repo/releases"
Write-Host "Determining latest release"
$json = Invoke-WebRequest $releases
$tag = ($json | ConvertFrom-Json)[0].tag_name
$file = ($json | ConvertFrom-Json)[0].assets[0].name
$download = "https://github.com/$repo/releases/download/$tag/$file"
$output = $PSScriptRoot + "\winget-latest.appxbundle"
Write-Host "Dowloading latest release"
Invoke-WebRequest -Uri $download -OutFile $output
Write-Host "Installing the package"
Add-AppxPackage -Path $output
}
Finally {
# Start installing the packages with winget
Get-Content .\winget.txt | ForEach-Object {
iex ("winget install -e " + $_)
}
}
7zip.7zip
Microsoft.PowerShell
GitHub.cli
AdoptOpenJDK.OpenJDK
Git.Git
Notepad++.Notepad++
Microsoft.dotNetFramework
Microsoft.dotnet
Yarn.Yarn
Google.Chrome
OpenJS.Nodejs
Nodist.Nodist
MRidgers.Clink
FarManager.FarManager
Microsoft.PowerToys
Microsoft.WindowsTerminal
Python.Python
PuTTY.PuTTY
WinSCP.WinSCP
dbeaver.dbeaver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment