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 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') } }