From efbaa6d3e51a3f2be04f39155d3f1068df3c5be0 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:00:10 +0200 Subject: [PATCH] remove write in "get" function --- Winget-AutoUpdate/WAU-Policies.ps1 | 9 ++++++++- Winget-AutoUpdate/functions/Get-WAUConfig.ps1 | 19 +++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1 index cbae962..e3eb61c 100644 --- a/Winget-AutoUpdate/WAU-Policies.ps1 +++ b/Winget-AutoUpdate/WAU-Policies.ps1 @@ -10,10 +10,17 @@ Daily update settings from policies . "$PSScriptRoot\functions\Get-WAUConfig.ps1" . "$PSScriptRoot\functions\Add-Shortcut.ps1" +#Check if GPO Management is enabled +$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue +if ($ActivateGPOManagement -eq 1) { + #Add (or update) tag to activate WAU-Policies scheduled task + New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null +} + #Get WAU settings $WAUConfig = Get-WAUConfig -#Check if GPO got applied from Get-WAUConfig +#Check if GPO got applied from Get-WAUConfig (tag) if ($WAUConfig.WAU_RunGPOManagement -eq 1) { #Log init diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 index ab5fa51..6f9855c 100644 --- a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 +++ b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 @@ -2,28 +2,23 @@ Function Get-WAUConfig { - #Check if GPO Management is enabled - $ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue - - if ($ActivateGPOManagement -eq 1) { - - #Add a tag to activate WAU-Policies scheduled task - New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null - - #Get all WAU Policies - $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue - } - #Get WAU Configurations from install config $WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -ErrorAction SilentlyContinue + #Check if GPO Management is enabled + $ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue + #If GPO Management is enabled, replace settings if ($ActivateGPOManagement -eq 1) { + #Get all WAU Policies + $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue + #Replace loaded configurations by ones from Policies $WAUPolicies.PSObject.Properties | ForEach-Object { $WAUConfig.PSObject.Properties.add($_) } + } #Return config