-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUpdateWinget
29 lines (27 loc) · 1.39 KB
/
UpdateWinget
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
##*===============================================
##* Find Latest Version of Winget
##*===============================================
function getNewestLink($match) {
$uri = "https://api.github.com/repos/microsoft/winget-cli/releases/latest"
Write-Verbose "[$((Get-Date).TimeofDay)] Getting information from $uri"
$get = Invoke-RestMethod -uri $uri -Method Get -UseBasicParsing -ErrorAction stop
Write-Verbose "[$((Get-Date).TimeofDay)] getting latest release"
$data = $get[0].assets | Where-Object name -Match $match
return $data.browser_download_url
}
$wingetUrl = getNewestLink("msixbundle")
$wingetLicenseUrl = getNewestLink("License1.xml")
##*===============================================
##* Install Winget
##*===============================================
Write-Host "Installing Winget"
$wingetPath = "winget.msixbundle"
Invoke-WebRequest -Uri $wingetUrl -OutFile $wingetPath
$wingetLicensePath = "license1.xml"
Invoke-WebRequest -Uri $wingetLicenseUrl -OutFile $wingetLicensePath
Add-AppxProvisionedPackage -Online -PackagePath $wingetPath -LicensePath $wingetLicensePath -ErrorAction SilentlyContinue
$path = [Environment]::GetEnvironmentVariable("PATH", "User")
$path = $path + ";" + [IO.Path]::Combine([Environment]::GetEnvironmentVariable("LOCALAPPDATA"), "Microsoft", "WindowsApps")
[Environment]::SetEnvironmentVariable("PATH", $path, "User")
Remove-Item $wingetPath
Remove-Item $wingetLicensePath