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