commit
c478bd483c
|
@ -181,20 +181,31 @@ function Install-Prerequisites {
|
|||
|
||||
function Install-WinGet {
|
||||
|
||||
Write-Host "`nChecking if Winget is installed" -ForegroundColor Yellow
|
||||
|
||||
#Check Package Install
|
||||
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" }
|
||||
|
||||
#Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
|
||||
If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") {
|
||||
|
||||
Write-Host "Winget is Installed" -ForegroundColor Green
|
||||
Write-Host "`nChecking if WinGet is installed/up to date" -ForegroundColor Yellow
|
||||
|
||||
#Check available WinGet version, if fail set version to the latest version as of 2023-10-08
|
||||
. "$PSScriptRoot\Winget-AutoUpdate\functions\Get-AvailableWinGetVersion.ps1"
|
||||
$AvailableWinGetVersion = Get-AvailableWinGetVersion
|
||||
if (!$AvailableWinGetVersion) {
|
||||
$AvailableWinGetVersion = "1.6.2771"
|
||||
}
|
||||
Else {
|
||||
|
||||
Write-Host "-> Winget is not installed:"
|
||||
#Check if WinGet is installed, if not set version to dummy...
|
||||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
||||
if (!$ResolveWingetPath) {
|
||||
$InstalledWinGetVersion = "0.0.0000"
|
||||
}
|
||||
else {
|
||||
#If multiple version, pick last one
|
||||
$WingetPath = $ResolveWingetPath[-1].Path
|
||||
$InstalledWinGetVersion = & $WingetPath --version
|
||||
$InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "")
|
||||
}
|
||||
|
||||
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
|
||||
if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) {
|
||||
|
||||
Write-Host "-> WinGet is not installed/up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available:" -ForegroundColor Red
|
||||
|
||||
#Check if $WingetUpdatePath exist
|
||||
if (!(Test-Path $WingetUpdatePath)) {
|
||||
|
@ -235,28 +246,42 @@ function Install-WinGet {
|
|||
}
|
||||
Remove-Item -Path $VCLibsFile -Force
|
||||
}
|
||||
|
||||
|
||||
#Download WinGet MSIXBundle
|
||||
Write-Host "-> Downloading Winget MSIXBundle for App Installer..."
|
||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||
Write-Host "-> Downloading WinGet MSIXBundle for App Installer..."
|
||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||
$WebClient = New-Object System.Net.WebClient
|
||||
$WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||
|
||||
#Install WinGet MSIXBundle in SYSTEM context
|
||||
try {
|
||||
Write-Host "-> Installing Winget MSIXBundle for App Installer..."
|
||||
Write-Host "-> Installing WinGet MSIXBundle for App Installer..."
|
||||
Add-AppxProvisionedPackage -Online -PackagePath "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
|
||||
Write-host "Winget MSIXBundle for App Installer installed successfully" -ForegroundColor Green
|
||||
Write-host "Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" -ForegroundColor Green
|
||||
|
||||
#Reset WinGet Sources
|
||||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
||||
if ($ResolveWingetPath) {
|
||||
#If multiple version, pick last one
|
||||
$WingetPath = $ResolveWingetPath[-1].Path
|
||||
& $WingetPath source reset --force
|
||||
#log
|
||||
Write-Host "-> WinGet sources reset." -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "Failed to intall Winget MSIXBundle for App Installer..." -ForegroundColor Red
|
||||
Write-Host "Failed to intall WinGet MSIXBundle for App Installer..." -ForegroundColor Red
|
||||
}
|
||||
|
||||
#Remove WinGet MSIXBundle
|
||||
Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
||||
|
||||
}
|
||||
|
||||
elseif ($AvailableWinGetVersion -match "-pre") {
|
||||
Write-Host "-> WinGet is up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available but only as a Pre-release" -ForegroundColor Yellow
|
||||
}
|
||||
else {
|
||||
Write-Host "-> WinGet is up to date: v$InstalledWinGetVersion" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
function Install-WingetAutoUpdate {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#Function to get the latest WinGet available version on Github
|
||||
Function Get-AvailableWinGetVersion {
|
||||
|
||||
#Get latest WinGet info
|
||||
$WinGeturl = 'https://api.github.com/repos/microsoft/winget-cli/releases/latest'
|
||||
|
||||
try {
|
||||
#Return latest version
|
||||
return ((Invoke-WebRequest $WinGeturl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
||||
}
|
||||
catch {
|
||||
return $false
|
||||
}
|
||||
|
||||
}
|
|
@ -17,48 +17,62 @@ function Invoke-PostUpdateActions {
|
|||
$null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -Confirm:$False -ErrorAction SilentlyContinue)
|
||||
}
|
||||
|
||||
#Check Package Install
|
||||
Write-ToLog "-> Checking if Winget is installed/up to date" "yellow"
|
||||
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" }
|
||||
|
||||
#Current: v1.5.2201 = 1.20.2201.0 = 2023.808.2243.0
|
||||
If ([Version]$TestWinGet.Version -ge "2023.808.2243.0") {
|
||||
|
||||
Write-ToLog "-> WinGet is Installed/up to date" "green"
|
||||
|
||||
}
|
||||
Else {
|
||||
|
||||
#Download WinGet MSIXBundle
|
||||
Write-ToLog "-> Not installed/up to date. Downloading WinGet..."
|
||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||
$WebClient = New-Object System.Net.WebClient
|
||||
$WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||
|
||||
#Install WinGet MSIXBundle
|
||||
try {
|
||||
Write-ToLog "-> Installing Winget MSIXBundle for App Installer..."
|
||||
Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
|
||||
Write-ToLog "-> Installed Winget MSIXBundle for App Installer" "green"
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> Failed to intall Winget MSIXBundle for App Installer..." "red"
|
||||
}
|
||||
|
||||
#Remove WinGet MSIXBundle
|
||||
Remove-Item -Path "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
||||
Write-ToLog "-> Checking if WinGet is installed/up to date" "yellow"
|
||||
|
||||
#Check available WinGet version, if fail set version to the latest version as of 2023-10-08
|
||||
$AvailableWinGetVersion = Get-AvailableWinGetVersion
|
||||
if (!$AvailableWinGetVersion) {
|
||||
$AvailableWinGetVersion = "1.6.2771"
|
||||
}
|
||||
|
||||
#Reset Winget Sources
|
||||
#Check installed WinGet version
|
||||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
||||
if ($ResolveWingetPath) {
|
||||
#If multiple version, pick last one
|
||||
$WingetPath = $ResolveWingetPath[-1].Path
|
||||
& $WingetPath source reset --force
|
||||
$InstalledWinGetVersion = & $WingetPath --version
|
||||
$InstalledWinGetVersion = $InstalledWinGetVersion.Replace("v", "")
|
||||
}
|
||||
|
||||
#log
|
||||
Write-ToLog "-> Winget sources reseted." "green"
|
||||
#Check if the current available WinGet isn't a Pre-release and if it's newer than the installed
|
||||
if (!($AvailableWinGetVersion -match "-pre") -and ($AvailableWinGetVersion -gt $InstalledWinGetVersion)) {
|
||||
|
||||
Write-ToLog "-> WinGet is not installed/up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available:" "red"
|
||||
|
||||
#Download WinGet MSIXBundle
|
||||
Write-ToLog "-> Downloading WinGet MSIXBundle for App Installer..."
|
||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||
$WebClient = New-Object System.Net.WebClient
|
||||
$WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||
|
||||
#Install WinGet MSIXBundle in SYSTEM context
|
||||
try {
|
||||
Write-ToLog "-> Installing WinGet MSIXBundle for App Installer..."
|
||||
Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
|
||||
Write-ToLog "-> Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" "green"
|
||||
|
||||
#Reset WinGet Sources
|
||||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
||||
if ($ResolveWingetPath) {
|
||||
#If multiple version, pick last one
|
||||
$WingetPath = $ResolveWingetPath[-1].Path
|
||||
& $WingetPath source reset --force
|
||||
#log
|
||||
Write-ToLog "-> WinGet sources reset." "green"
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-ToLog "-> Failed to intall WinGet MSIXBundle for App Installer..." "red"
|
||||
}
|
||||
|
||||
#Remove WinGet MSIXBundle
|
||||
Remove-Item -Path "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
||||
}
|
||||
elseif ($AvailableWinGetVersion -match "-pre") {
|
||||
Write-ToLog "-> WinGet is up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available but only as a Pre-release" "yellow"
|
||||
}
|
||||
else {
|
||||
Write-ToLog "-> WinGet is up to date: v$InstalledWinGetVersion" "green"
|
||||
}
|
||||
|
||||
#Create WAU Regkey if not present
|
||||
|
|
Loading…
Reference in New Issue