update pinned app, if pinned version is lower than available version

pull/746/head
Fabian Seitz 2024-10-23 18:58:40 +02:00
parent c0ea06b95c
commit 83d5467e08
3 changed files with 62 additions and 28 deletions

View File

@ -111,6 +111,8 @@ If `-ListPath` is set to **GPO** the Black/White List can be managed from within
**EXCLUDEPINNEDAPPS**<br>
Default value 0. Set `EXCLUDEPINNEDAPPS=1` to enable including pinned winget apps to Blacklist. If you are using a whitelist, this option will be ignored. [More details.](https://learn.microsoft.com/en-us/windows/package-manager/winget/pinning)
If you are using a wildcard in the blacklist (f.e. Microsoft.Edge*), the app will always be skipped, even if the pinned version is less than the latest available version.
**MODSPATH**<br>
Get Mods from external Path (**URL/UNC/Local/AzureBlob**) - download/copy to `mods` in Winget-AutoUpdate installation location if external mods are newer.<br>
For **URL**: This requires a site directory with **Directory Listing Enabled** and no index page overriding the listing of files (or an index page with href listing of all the **Mods** to be downloaded):

View File

@ -284,7 +284,7 @@ if (Test-Network) {
New-Item "$WorkingDir\logs\error.txt" -Value "Blacklist doesn't exist in GPO" -Force
Exit 1
}
foreach ($app in $toSkip) { Write-ToLog "Exclude app ${app}" }
foreach ($app in $toSkip) { Write-ToLog "Exclude app $($app.AppID) $($app.PinnedVersion)" }
}
}
@ -348,11 +348,18 @@ if (Test-Network) {
Write-ToLog "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
}
#if app is in "excluded list", skip it
elseif ($toSkip -contains $app.Id) {
elseif ($toSkip.AppID -contains $app.Id) {
if ($toSkip.PinnedVersion) {
$regexPattern = $toSkip.PinnedVersion -replace '\.', '\.' -replace '\*', '.*'
$regexPattern = "^$regexPattern$"
if ($app.AvailableVersion -match $regexPattern) {
Update-App $app
}
}
Write-ToLog "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
}
#if app with wildcard is in "excluded list", skip it
elseif ($toSkip | Where-Object { $app.Id -like $_ }) {
elseif ($toSkip.AppID | Where-Object { $app.Id -like $_ }) {
Write-ToLog "$($app.Name) : Skipped upgrade because it is *wildcard* in the excluded app list" "Gray"
}
# else, update it

View File

@ -1,25 +1,24 @@
#Function to get the Block List apps
function Get-ExcludedApps {
$AppIDs = @()
#blacklist in registry
if ($GPOList) {
Write-ToLog "-> Excluded apps from GPO is activated"
if (Test-Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList") {
$ValueNames = (Get-Item -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList").Property
foreach ($ValueName in $ValueNames) {
$AppIDs += (Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList" -Name $ValueName).Trim()
$AppIDs += [PSCustomObject]@{
AppID = (Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList" -Name $ValueName).Trim()
PinnedVersion = $null
}
}
Write-ToLog "-> Successsfully loaded excluded apps list."
Write-ToLog "-> Successfully loaded excluded apps list."
}
}
#blacklist pulled from URI
elseif ($URIList) {
$RegPath = "$WAU_GPORoot";
$RegValueName = 'WAU_URIList';
@ -32,33 +31,41 @@ function Get-ExcludedApps {
if ($resp.BaseResponse.StatusCode -eq [System.Net.HttpStatusCode]::OK) {
$resp.Content.Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries) |
ForEach-Object {
$AppIds += $_
$AppIDs += [PSCustomObject]@{
AppID = $_
PinnedVersion = $null
}
}
Write-ToLog "-> Successsfully loaded excluded apps list."
Write-ToLog "-> Successfully loaded excluded apps list."
}
}
}
}
#blacklist pulled from local file
elseif (Test-Path "$WorkingDir\excluded_apps.txt") {
$AppIDs = (Get-Content -Path "$WorkingDir\excluded_apps.txt").Trim()
Write-ToLog "-> Successsfully loaded local excluded apps list."
$AppIDs = (Get-Content -Path "$WorkingDir\excluded_apps.txt").Trim() | ForEach-Object {
[PSCustomObject]@{
AppID = $_
PinnedVersion = $null
}
}
Write-ToLog "-> Successfully loaded local excluded apps list."
}
#blacklist pulled from default file
elseif (Test-Path "$WorkingDir\config\default_excluded_apps.txt") {
$AppIDs = (Get-Content -Path "$WorkingDir\config\default_excluded_apps.txt").Trim()
Write-ToLog "-> Successsfully loaded default excluded apps list."
$AppIDs = (Get-Content -Path "$WorkingDir\config\default_excluded_apps.txt").Trim() | ForEach-Object {
[PSCustomObject]@{
AppID = $_
PinnedVersion = $null
}
}
Write-ToLog "-> Successfully loaded default excluded apps list."
}
$WAUExcludePinnedApps = $WAUConfig.WAU_ExcludePinnedApps
if ($WAUExcludePinnedApps -eq 1) {
#blacklist pinned winget apps
$pinnedAppsResult = & $Winget pin list | Where-Object { $_ -notlike " *" } | Out-String
$pinnedAppsResult = & winget pin list | Where-Object { $_ -notlike " *" } | Out-String
if (!($pinnedAppsResult -match "-----")) {
Write-ToLog "-> No pinned winget apps found, nothing to exclude."
} else {
@ -75,28 +82,46 @@ function Get-ExcludedApps {
$fl = $fl - 1
# Get header titles and calculate start positions of each column
$index = $lines[$fl] -split '\s{2,}'
# Split the header line using a regex that matches one or more spaces or tabs
$index = $lines[$fl] -split '\s{1,}'
# Use the index of the second column to find the start positions of each column
$idStart = $lines[$fl].IndexOf($index[1])
$versionStart = $lines[$fl].IndexOf($index[2])
$containsGating = $lines | Where-Object { $_.Trim() -like "*Gating*" }
if ($containsGating) {
$pinnedAppVersionStart = $lines[$fl].IndexOf($index[5])
}
# Now cycle through the real package lines and split accordingly
For ($i = $fl + 2; $i -lt $lines.Length; $i++) {
$line = $lines[$i] -replace "[\u2026]", " " # Fix "..." in long names
$line = $lines[$i] -replace "[\u2026]|", " " # Fix "..." in long names
if (-Not ($line.StartsWith("-----"))) {
# (Alphanumeric | Literal . | Alphanumeric) - the only unique thing in common for lines with applications
if ($line -match "\w\.\w") {
$softwareId = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
if ($line -like "*Gating*") {
$pinnedVersion = $line.Substring($pinnedAppVersionStart).TrimStart() # Get the pinned version
$AdditionalLogText = "with version $pinnedVersion"
} else {
$pinnedVersion = $null
$AdditionalLogText = $null
}
if ($null -ne $softwareId) {
# Add the extracted software ID to the list
$AppIds += $softwareId
Write-ToLog "Excluding $softwareId from WAU updates, as this app is pinned in winget"
# Add the extracted software ID and version to the list
$AppIDs += [PSCustomObject]@{
AppID = $softwareId
PinnedVersion = $pinnedVersion
}
Write-ToLog "Excluding $softwareId from WAU updates, as this app is pinned in winget $AdditionalLogText"
}
}
}
}
}
}
return $AppIDs | Where-Object { $_.length -gt 0 }
return $AppIDs | Where-Object { $_.AppID -and $_.AppID.length -gt 0 }
}