commit
c478bd483c
|
@ -181,20 +181,31 @@ function Install-Prerequisites {
|
||||||
|
|
||||||
function Install-WinGet {
|
function Install-WinGet {
|
||||||
|
|
||||||
Write-Host "`nChecking if Winget is installed" -ForegroundColor Yellow
|
Write-Host "`nChecking if WinGet is installed/up to date" -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
|
|
||||||
|
|
||||||
|
#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
|
#Check if $WingetUpdatePath exist
|
||||||
if (!(Test-Path $WingetUpdatePath)) {
|
if (!(Test-Path $WingetUpdatePath)) {
|
||||||
|
@ -237,26 +248,40 @@ function Install-WinGet {
|
||||||
}
|
}
|
||||||
|
|
||||||
#Download WinGet MSIXBundle
|
#Download WinGet MSIXBundle
|
||||||
Write-Host "-> Downloading Winget MSIXBundle for App Installer..."
|
Write-Host "-> Downloading WinGet MSIXBundle for App Installer..."
|
||||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||||
$WebClient = New-Object System.Net.WebClient
|
$WebClient = New-Object System.Net.WebClient
|
||||||
$WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
$WebClient.DownloadFile($WinGetURL, "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||||
|
|
||||||
#Install WinGet MSIXBundle in SYSTEM context
|
#Install WinGet MSIXBundle in SYSTEM context
|
||||||
try {
|
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
|
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 {
|
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 WinGet MSIXBundle
|
||||||
Remove-Item -Path "$WingetUpdatePath\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
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 {
|
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)
|
$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"
|
||||||
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"
|
|
||||||
|
|
||||||
|
#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"
|
||||||
}
|
}
|
||||||
Else {
|
|
||||||
|
#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
|
||||||
|
$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-ToLog "-> WinGet is not installed/up to date (v$InstalledWinGetVersion) - v$AvailableWinGetVersion is available:" "red"
|
||||||
|
|
||||||
#Download WinGet MSIXBundle
|
#Download WinGet MSIXBundle
|
||||||
Write-ToLog "-> Not installed/up to date. Downloading WinGet..."
|
Write-ToLog "-> Downloading WinGet MSIXBundle for App Installer..."
|
||||||
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.5.2201/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
|
||||||
$WebClient = New-Object System.Net.WebClient
|
$WebClient = New-Object System.Net.WebClient
|
||||||
$WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
$WebClient.DownloadFile($WinGetURL, "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
|
||||||
|
|
||||||
#Install WinGet MSIXBundle
|
#Install WinGet MSIXBundle in SYSTEM context
|
||||||
try {
|
try {
|
||||||
Write-ToLog "-> Installing Winget MSIXBundle for App Installer..."
|
Write-ToLog "-> Installing WinGet MSIXBundle for App Installer..."
|
||||||
Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
|
Add-AppxProvisionedPackage -Online -PackagePath "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
|
||||||
Write-ToLog "-> Installed Winget MSIXBundle for App Installer" "green"
|
Write-ToLog "-> Winget MSIXBundle (v$AvailableWinGetVersion) for App Installer installed successfully" "green"
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-ToLog "-> Failed to intall Winget MSIXBundle for App Installer..." "red"
|
|
||||||
}
|
|
||||||
|
|
||||||
#Remove WinGet MSIXBundle
|
#Reset WinGet Sources
|
||||||
Remove-Item -Path "$($WAUConfig.InstallLocation)\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -Force -ErrorAction Continue
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#Reset Winget Sources
|
|
||||||
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_*__8wekyb3d8bbwe\winget.exe" | Sort-Object { [version]($_.Path -replace '^[^\d]+_((\d+\.)*\d+)_.*', '$1') }
|
||||||
if ($ResolveWingetPath) {
|
if ($ResolveWingetPath) {
|
||||||
#If multiple version, pick last one
|
#If multiple version, pick last one
|
||||||
$WingetPath = $ResolveWingetPath[-1].Path
|
$WingetPath = $ResolveWingetPath[-1].Path
|
||||||
& $WingetPath source reset --force
|
& $WingetPath source reset --force
|
||||||
|
|
||||||
#log
|
#log
|
||||||
Write-ToLog "-> Winget sources reseted." "green"
|
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
|
#Create WAU Regkey if not present
|
||||||
|
|
Loading…
Reference in New Issue