2023-10-12 02:22:15 +00:00
|
|
|
#Function to download and update WinGet
|
2023-10-11 20:19:34 +00:00
|
|
|
|
2023-10-31 11:43:15 +00:00
|
|
|
Function Update-WinGet {
|
2023-10-11 20:19:34 +00:00
|
|
|
|
2023-10-31 11:43:15 +00:00
|
|
|
Write-ToLog "Checking if WinGet is installed/up to date." "Yellow"
|
2023-10-12 17:42:01 +00:00
|
|
|
|
2023-10-31 11:43:15 +00:00
|
|
|
#Get latest WinGet info
|
|
|
|
$WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
|
2023-10-11 20:19:34 +00:00
|
|
|
|
|
|
|
try {
|
2023-10-31 11:43:15 +00:00
|
|
|
#Return latest version
|
2023-10-31 11:59:25 +00:00
|
|
|
$WinGetAvailableVersion = ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
2023-10-31 11:43:15 +00:00
|
|
|
}
|
|
|
|
catch {
|
|
|
|
#if fail set version to the latest version as of 2023-10-08
|
2023-10-31 11:59:25 +00:00
|
|
|
$WinGetAvailableVersion = "1.6.2771"
|
2023-10-31 11:43:15 +00:00
|
|
|
}
|
2023-10-11 20:19:34 +00:00
|
|
|
|
2023-10-31 11:43:15 +00:00
|
|
|
try {
|
|
|
|
#Get Admin Context Winget Location
|
2023-10-30 17:42:58 +00:00
|
|
|
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
|
|
|
|
#If multiple versions, pick most recent one
|
|
|
|
$WingetCmd = $WingetInfo[-1].FileName
|
2023-10-31 11:43:15 +00:00
|
|
|
#Get current Winget Version
|
|
|
|
$WingetInstalledVersion = [regex]::match((& $WingetCmd -v), '((\d+\.)(\d+\.)(\d+))').Groups[1].Value
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|
|
|
|
catch {
|
2023-10-31 11:43:15 +00:00
|
|
|
Write-ToLog "-> WinGet is not installed" "Red"
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|
|
|
|
|
2023-10-31 11:43:15 +00:00
|
|
|
#Check if the current available WinGet is newer than the installed
|
|
|
|
if ($WinGetAvailableVersion -gt $WinGetInstalledVersion) {
|
|
|
|
|
|
|
|
#Check if Microsoft.VCLibs.140.00.UWPDesktop is installed
|
|
|
|
if (!(Get-AppxPackage -Name 'Microsoft.VCLibs.140.00.UWPDesktop' -AllUsers)) {
|
|
|
|
try {
|
2023-10-31 12:05:09 +00:00
|
|
|
#Download
|
|
|
|
$VCLibsUrl = "https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
|
|
|
$VCLibsFile = "$env:TEMP\Microsoft.VCLibs.x64.14.00.Desktop.appx"
|
|
|
|
Write-ToLog "-> Downloading Microsoft.VCLibs.140.00.UWPDesktop..."
|
|
|
|
Invoke-RestMethod -Uri $VCLibsUrl -OutFile $VCLibsFile
|
|
|
|
#Install
|
2023-10-31 11:43:15 +00:00
|
|
|
Write-ToLog "-> Installing Microsoft.VCLibs.140.00.UWPDesktop..."
|
|
|
|
Add-AppxProvisionedPackage -Online -PackagePath $VCLibsFile -SkipLicense | Out-Null
|
|
|
|
Write-ToLog "-> Microsoft.VCLibs.140.00.UWPDesktop installed successfully." "Green"
|
|
|
|
}
|
|
|
|
catch {
|
|
|
|
Write-ToLog "-> Failed to intall Microsoft.VCLibs.140.00.UWPDesktop..." "Red"
|
|
|
|
}
|
|
|
|
Remove-Item -Path $VCLibsFile -Force
|
|
|
|
}
|
|
|
|
|
|
|
|
#Install WinGet MSIXBundle in SYSTEM context
|
|
|
|
try {
|
2023-10-31 12:05:09 +00:00
|
|
|
#Download WinGet MSIXBundle
|
|
|
|
Write-ToLog "-> Downloading WinGet MSIXBundle for App Installer..."
|
|
|
|
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$WinGetAvailableVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
|
|
|
$WingetInstaller = "$env:TEMP\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
|
|
|
Invoke-RestMethod -Uri $WinGetURL -OutFile $WingetInstaller
|
|
|
|
|
|
|
|
#Install
|
2023-10-31 11:43:15 +00:00
|
|
|
Write-ToLog "-> Installing WinGet MSIXBundle for App Installer..."
|
|
|
|
Add-AppxProvisionedPackage -Online -PackagePath $WingetInstaller -SkipLicense | Out-Null
|
|
|
|
Write-ToLog "-> WinGet MSIXBundle (v$WinGetAvailableVersion) for App Installer installed successfully!" "green"
|
|
|
|
|
|
|
|
#Reset WinGet Sources
|
|
|
|
$WingetInfo = (Get-Item "$env:ProgramFiles\WindowsApps\Microsoft.DesktopAppInstaller_*_8wekyb3d8bbwe\winget.exe").VersionInfo | Sort-Object -Property FileVersionRaw
|
|
|
|
#If multiple versions, pick most recent one
|
|
|
|
$WingetCmd = $WingetInfo[-1].FileName
|
|
|
|
& $WingetCmd source reset --force
|
2023-11-02 17:22:29 +00:00
|
|
|
Write-ToLog "-> WinGet sources reset." "green"
|
2023-11-01 21:50:44 +00:00
|
|
|
$return = "success"
|
2023-10-31 11:43:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
catch {
|
2023-11-02 17:22:29 +00:00
|
|
|
Write-ToLog "-> Failed to install WinGet MSIXBundle for App Installer..." "red"
|
2023-11-01 21:32:50 +00:00
|
|
|
#Force Store Apps to update
|
2023-10-31 11:43:15 +00:00
|
|
|
Update-StoreApps
|
2023-11-01 21:50:44 +00:00
|
|
|
$return = "fail"
|
2023-10-31 11:43:15 +00:00
|
|
|
}
|
2023-11-02 17:22:29 +00:00
|
|
|
|
2023-11-01 21:50:44 +00:00
|
|
|
#Remove WinGet MSIXBundle
|
|
|
|
Remove-Item -Path $WingetInstaller -Force -ErrorAction SilentlyContinue
|
|
|
|
|
|
|
|
#Return status
|
|
|
|
return $return
|
2023-10-31 11:43:15 +00:00
|
|
|
}
|
|
|
|
else {
|
2023-11-02 17:22:29 +00:00
|
|
|
Write-ToLog "-> WinGet is up to date: v$WinGetInstalledVersion" "Green"
|
2023-11-01 18:28:25 +00:00
|
|
|
return "current"
|
2023-10-31 11:43:15 +00:00
|
|
|
}
|
2023-10-11 20:19:34 +00:00
|
|
|
}
|