Files
winutil/functions/private/Install-WinUtilWinget.ps1
T

50 lines
1.7 KiB
PowerShell
Raw Normal View History

2023-07-27 16:06:41 -05:00
function Get-LatestHash {
$shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url
2023-10-19 17:12:55 -05:00
2023-07-27 16:06:41 -05:00
$shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt'
$WebClient.DownloadFile($shaUrl, $shaFile)
2023-10-19 17:12:55 -05:00
2023-07-27 16:06:41 -05:00
Get-Content $shaFile
2023-10-19 17:12:55 -05:00
}
2023-07-27 16:06:41 -05:00
+3
2023-03-07 12:28:00 -08:00
function Install-WinUtilWinget {
2023-10-19 17:12:55 -05:00
+3
2023-03-07 12:28:00 -08:00
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Installs Winget if it is not already installed
+12
2023-11-28 16:11:11 -06:00
.DESCRIPTION
This function will download the latest version of winget and install it. If winget is already installed, it will do nothing.
+3
2023-03-07 12:28:00 -08:00
#>
Try{
Write-Host "Checking if Winget is Installed..."
if (Test-WinUtilPackageManager -winget) {
2023-10-19 17:12:55 -05:00
# Checks if winget executable exists and if the Windows Version is 1809 or higher
+3
2023-03-07 12:28:00 -08:00
Write-Host "Winget Already Installed"
return
}
2023-10-19 17:12:55 -05:00
# Gets the computer's information
+3
2023-03-07 12:28:00 -08:00
if ($null -eq $sync.ComputerInfo){
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
}
Else {
$ComputerInfo = $sync.ComputerInfo
}
if (($ComputerInfo.WindowsVersion) -lt "1809") {
2023-10-19 17:12:55 -05:00
# Checks if Windows Version is too old for winget
+3
2023-03-07 12:28:00 -08:00
Write-Host "Winget is not supported on this version of Windows (Pre-1809)"
return
}
2024-02-07 18:11:40 -06:00
Write-Host "Running Alternative Installer and Direct Installing"
Start-Process -Verb runas -FilePath powershell.exe -ArgumentList "choco install winget"
Write-Host "Winget Installed"
+3
2023-03-07 12:28:00 -08:00
}
Catch{
throw [WingetFailedInstall]::new('Failed to install')
}
2024-02-07 18:11:40 -06:00
}