From e5183698518cfb374a06ce19c89f97168851de63 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Fri, 20 Jan 2023 03:59:27 +0100 Subject: [PATCH] Finally a GPO List Array that works with -contains --- Winget-AutoUpdate/Winget-Upgrade.ps1 | 9 +++++++-- Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 | 14 +++++++++++++- Winget-AutoUpdate/functions/Get-IncludedApps.ps1 | 13 ++++++++++++- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1 index e9fc423..0e7b915 100644 --- a/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -197,6 +197,11 @@ if (Test-Network) { $toSkip = Get-ExcludedApps } + #Fix the array if GPO List! + if ($GPOList) { + $toSkip = $toSkip.Data + } + #Get outdated Winget packages Write-Log "Checking application updates on Winget Repository..." "yellow" $outdated = Get-WingetOutdatedApps @@ -231,7 +236,7 @@ if (Test-Network) { if ($UseWhiteList) { #For each app, notify and update foreach ($app in $outdated) { - if (($toUpdate -match $app.Id) -and $($app.Version) -ne "Unknown") { + if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") { Update-App $app } #if current app version is unknown @@ -248,7 +253,7 @@ if (Test-Network) { else { #For each app, notify and update foreach ($app in $outdated) { - if (-not ($toSkip -match $app.Id) -and $($app.Version) -ne "Unknown") { + if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") { Update-App $app } #if current app version is unknown diff --git a/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 b/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 index 8961601..187b6c3 100644 --- a/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 @@ -4,7 +4,19 @@ function Get-ExcludedApps { if ($GPOList) { - return Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList" + $Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList\' + $ValueNames = (Get-Item -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\BlackList").Property + + foreach ($ValueName in $ValueNames) { + $AppIDs = [Microsoft.Win32.Registry]::GetValue($Key, $ValueName, $false) + [PSCustomObject]@{ + Value = $ValueName + Data = $AppIDs + } + } + + return $AppIDs + } elseif (Test-Path "$WorkingDir\excluded_apps.txt") { diff --git a/Winget-AutoUpdate/functions/Get-IncludedApps.ps1 b/Winget-AutoUpdate/functions/Get-IncludedApps.ps1 index ce3e636..06f2d6a 100644 --- a/Winget-AutoUpdate/functions/Get-IncludedApps.ps1 +++ b/Winget-AutoUpdate/functions/Get-IncludedApps.ps1 @@ -4,7 +4,18 @@ function Get-IncludedApps { if ($GPOList) { - return Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\WhiteList" + $Key = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\WhiteList\' + $ValueNames = (Get-Item -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate\WhiteList").Property + + foreach ($ValueName in $ValueNames) { + $AppIDs = [Microsoft.Win32.Registry]::GetValue($Key, $ValueName, $false) + [PSCustomObject]@{ + Value = $ValueName + Data = $AppIDs + } + } + + return $AppIDs } elseif (Test-Path "$WorkingDir\included_apps.txt") {