# Script to install winget. # Technolog Networks, 2024-07-26 # iRaven # Updated 2025-04-03 to get the legitimate install method MS recommends to use here. # https://learn.microsoft.com/en-us/windows/iot/iot-enterprise/deployment/install-winget-windows-iot Start-Transcript -Path "c:\irnh\Install-WinGet.log" -Append # See if the shit we need exists. Function Check-WinGet-Install { try { winget --version Write-Host "WinGet already exists!" return $true } catch { Write-Host "WinGet does not exist!" return $false } } Function Check-VCLibs { if ((Get-AppxPackage).Name -like "Microsoft.VCLibs.140.00.UWPDesktop" ) {return $true} else {return $false} } Function Install-VCLibs { if (Check-VCLibs) { Write-Output "VCLibs.UWPDesktop is already installed." } else { cmd.exe /c "curl -L -o c:\irnh\vclibs.14.00.Desktop.appx https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx" try { Add-AppxPackage -Path "c:\irnh\vclibs.14.00.Desktop.appx" # Add-AppxProvisionedPackage -Online -PackagePath "c:\irnh\vclibs.14.00.Desktop.appx" -SkipLicense Write-Output "VCLibs.UWPDesktop was installed." } catch { Write-Output "VCLibs.UWPDesktop could not be installed." } } } Function Install-WinGet { Write-Host "Checking latest version..." $WGLatestVer = (irm https://api.github.com/repos/microsoft/winget-cli/releases/latest).tag_name $WGDomainVer = type "\\technolog.net\SYSVOL\technolog.net\SoftwareDeploy\wingetlatestver.txt" if ($WGDomainVer -eq $WGLatestVer) { # If the version we have on our domain controllers is the latest, proceed with the offline copy. Write-Output "Domain Controllers has the latest version $WGDomainVer; using that." try { Add-AppxPackage -Path "\\technolog.net\SYSVOL\technolog.net\SoftwareDeploy\winget.msixbundle" Add-AppxProvisionedPackage -Online -PackagePath "\\technolog.net\SYSVOL\technolog.net\SoftwareDeploy\winget.msixbundle" -LicensePath "\\technolog.net\SYSVOL\technolog.net\SoftwareDeploy\wingetlic.xml" Write-Output "WinGet was successfully installed." } catch { Write-Output "WinGet could not be installed." } } else { # If the version we have on our domain controllers is NOT the latest, we have to get it online. Write-Host "Internet has the latest copy; downloading WinGet from Microsoft." cmd.exe /c "curl -L -o c:\irnh\winget.msixbundle https://aka.ms/getwinget" # I hate IWR. lol # download latest lic file foreach ($url in (irm https://api.github.com/repos/microsoft/winget-cli/releases/latest).assets.browser_download_url){ if ($url -like "*.xml") {cmd.exe /c "curl -L -o c:\irnh\wingetlic.xml $url"} # I hate IWR. lol } try { # Add-AppxPackage -Path "c:\irnh\winget.msixbundle" Add-AppxPackage -Path "c:\irnh\winget.msixbundle" Add-AppxProvisionedPackage -Online -PackagePath "c:\irnh\winget.msixbundle" -LicensePath "c:\irnh\wingetlic.xml" Write-Output "WinGet was successfully installed." } catch { Write-Output "WinGet could not be installed." } } } # Main script if (!(Check-WinGet-Install)) { Install-VCLibs Install-WinGet } Stop-Transcript