2023-03-07 14:28:00 -06:00
|
|
|
function Install-WinUtilWinget {
|
|
|
|
|
|
|
|
<#
|
|
|
|
|
|
|
|
.DESCRIPTION
|
|
|
|
Function is meant to ensure winget is installed
|
|
|
|
|
|
|
|
#>
|
|
|
|
Try{
|
|
|
|
Write-Host "Checking if Winget is Installed..."
|
|
|
|
if (Test-WinUtilPackageManager -winget) {
|
|
|
|
#Checks if winget executable exists and if the Windows Version is 1809 or higher
|
|
|
|
Write-Host "Winget Already Installed"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
#Gets the computer's information
|
|
|
|
if ($null -eq $sync.ComputerInfo){
|
|
|
|
$ComputerInfo = Get-ComputerInfo -ErrorAction Stop
|
|
|
|
}
|
|
|
|
Else {
|
|
|
|
$ComputerInfo = $sync.ComputerInfo
|
|
|
|
}
|
|
|
|
|
|
|
|
if (($ComputerInfo.WindowsVersion) -lt "1809") {
|
|
|
|
#Checks if Windows Version is too old for winget
|
|
|
|
Write-Host "Winget is not supported on this version of Windows (Pre-1809)"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
#Gets the Windows Edition
|
|
|
|
$OSName = if ($ComputerInfo.OSName) {
|
|
|
|
$ComputerInfo.OSName
|
|
|
|
}else {
|
|
|
|
$ComputerInfo.WindowsProductName
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((($OSName.IndexOf("LTSC")) -ne -1) -or ($OSName.IndexOf("Server") -ne -1)) -and (($ComputerInfo.WindowsVersion) -ge "1809")) {
|
|
|
|
|
|
|
|
Write-Host "Running Alternative Installer for LTSC/Server Editions"
|
|
|
|
|
|
|
|
# Switching to winget-install from PSGallery from asheroto
|
|
|
|
# Source: https://github.com/asheroto/winget-installer
|
|
|
|
|
2023-05-09 13:14:27 -05:00
|
|
|
#adding the code from the asheroto repo
|
|
|
|
Set-ExecutionPolicy RemoteSigned -force
|
|
|
|
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
|
|
|
|
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
|
|
|
Install-Script -Name winget-install -force
|
|
|
|
winget-instal
|
|
|
|
|
|
|
|
|
2023-03-07 14:28:00 -06:00
|
|
|
Start-Process powershell.exe -Verb RunAs -ArgumentList "-command irm https://raw.githubusercontent.com/ChrisTitusTech/winutil/$BranchToUse/winget.ps1 | iex | Out-Host" -WindowStyle Normal -ErrorAction Stop
|
|
|
|
|
|
|
|
if(!(Test-WinUtilPackageManager -winget)){
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
#Installing Winget from the Microsoft Store
|
|
|
|
Write-Host "Winget not found, installing it now."
|
|
|
|
Start-Process "ms-appinstaller:?source=https://aka.ms/getwinget"
|
|
|
|
$nid = (Get-Process AppInstaller).Id
|
|
|
|
Wait-Process -Id $nid
|
|
|
|
|
|
|
|
if(!(Test-WinUtilPackageManager -winget)){
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Write-Host "Winget Installed"
|
|
|
|
}
|
|
|
|
Catch{
|
|
|
|
throw [WingetFailedInstall]::new('Failed to install')
|
|
|
|
}
|
|
|
|
}
|