Files
scripts/Install-WinGet.ps1
2025-09-06 02:32:52 -05:00

107 lines
3.7 KiB
PowerShell

# 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 Check-MSXaml {
if ((Get-AppxPackage).Name -like "Microsoft.UI.Xaml*" ) {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-MSXaml {
if (Check-MSXaml) {
Write-Output "Microsoft.UI.Xaml is already installed."
} else {
cmd.exe /c "curl -L -o c:\irnh\msuixaml.zip https://www.nuget.org/api/v2/package/Microsoft.UI.Xaml"
try {
Expand-Archive c:\irnh\msuixaml.zip
Add-AppPackage .\msuixaml\tools\AppX\x64\Release\*.appx
Write-Output "Microsoft.UI.Xaml was installed."
} catch {
Write-Output "Microsoft.UI.Xaml 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" -Verbose
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."
# download latest files
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
if ($url -like "*.msixbundle")
{cmd.exe /c "curl -L -o c:\irnh\winget.msixbundle $url"} # I hate IWR. lol
}
try {
# Add-AppxPackage -Path "c:\irnh\winget.msixbundle"
Add-AppxPackage -Path "c:\irnh\winget.msixbundle" -Verbose
Add-AppxProvisionedPackage -Online -PackagePath "c:\irnh\winget.msixbundle" -LicensePath "c:\irnh\wingetlic.xml" -Verbose
$winget = winget -v
if ($winget) {
Write-Output "WinGet was successfully installed."
}
} catch {
Write-Output "WinGet could not be installed."
}
}
}
# Main script
if (!(Check-WinGet-Install)) {
Install-VCLibs
Install-MSXaml
Install-WinGet
}
Stop-Transcript