From 48cabc23b10d4a8570c86214f545a44b4872f030 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 01:15:01 +0200
Subject: [PATCH 01/14] First shot
---
Winget-AutoUpdate-Install.ps1 | 10 +-
Winget-AutoUpdate/WAU-Policies.ps1 | 65 ++++
Winget-AutoUpdate/Winget-Upgrade.ps1 | 16 +-
Winget-AutoUpdate/functions/Get-Policies.ps1 | 364 ------------------
Winget-AutoUpdate/functions/Get-WAUConfig.ps1 | 26 ++
.../functions/Invoke-PostUpdateActions.ps1 | 1 +
6 files changed, 103 insertions(+), 379 deletions(-)
create mode 100644 Winget-AutoUpdate/WAU-Policies.ps1
delete mode 100644 Winget-AutoUpdate/functions/Get-Policies.ps1
create mode 100644 Winget-AutoUpdate/functions/Get-WAUConfig.ps1
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index 98c0163..7922ca4 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -246,7 +246,7 @@ function Install-WinGet {
}
Remove-Item -Path $VCLibsFile -Force
}
-
+
#Download WinGet MSIXBundle
Write-Host "-> Downloading WinGet MSIXBundle for App Installer..."
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v$AvailableWinGetVersion/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
@@ -393,6 +393,13 @@ function Install-WingetAutoUpdate {
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
+ $taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\WAU-Policies.ps1`""
+ $tasktrigger = New-ScheduledTaskTrigger -Daily -At 6am
+ $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
+ $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
+ $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger
+ Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Policies' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
+
#Set task readable/runnable for all users
$scheduler = New-Object -ComObject "Schedule.Service"
$scheduler.Connect()
@@ -425,6 +432,7 @@ function Install-WingetAutoUpdate {
New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $MaxLogFiles -PropertyType DWord -Force | Out-Null
New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $MaxLogSize -PropertyType DWord -Force | Out-Null
New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null
+ New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $UpdatesInterval -Force | Out-Null
if ($UpdatesAtLogon) {
New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value 1 -PropertyType DWord -Force | Out-Null
}
diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1
new file mode 100644
index 0000000..3632b0b
--- /dev/null
+++ b/Winget-AutoUpdate/WAU-Policies.ps1
@@ -0,0 +1,65 @@
+<#
+.SYNOPSIS
+Handle GPO/Polices
+
+.DESCRIPTION
+Daily update settings from policies
+#>
+
+#Import functions
+. "$PSScriptRoot\functions\Get-WAUConfig.ps1"
+. "$PSScriptRoot\functions\Add-Shortcut.ps1"
+
+#Get WAU settings
+$WAUConfig = Get-WAUConfig
+
+#Check if GPO already applied at least once to this machine (ManagementTag)
+if ($WAUConfig.WAU_ManagementTag -eq 1) {
+
+ #Update 'Winget-AutoUpdate' scheduled task settings
+ $taskTriggers = @()
+ if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) {
+ $tasktriggers += New-ScheduledTaskTrigger -AtLogOn
+ }
+ if ($WAUConfig.WAU_UpdatesInterval -eq "Daily") {
+ $tasktriggers += New-ScheduledTaskTrigger -Daily -At $UpdatesAtTime
+ }
+ elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiDaily") {
+ $tasktriggers += New-ScheduledTaskTrigger -Daily -At $UpdatesAtTime -DaysInterval 2
+ }
+ elseif ($WAUConfig.WAU_UpdatesInterval -eq "Weekly") {
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2
+ }
+ elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiWeekly") {
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 2
+ }
+ elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") {
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
+ }
+ if ($taskTriggers) {
+ Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue | Set-ScheduledTask -Trigger $taskTriggers
+ }
+
+ #Update Desktop shortcut
+ $DesktopShortcut = "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"
+ if (($WAUConfig.WAU_DesktopShortcut -eq 1) -and !(Test-Path $DesktopShortcut)) {
+ Add-Shortcut "wscript.exe" $DesktopShortcut "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
+ }
+ elseif ($WAUConfig.WAU_DesktopShortcut -ne 1) {
+ Remove-Item -Path $DesktopShortcut -Force | Out-Null
+ }
+
+ #Update Start Menu shortcuts
+ $StartMenuShortcut = "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)"
+ if (($WAUConfig.WAU_StartMenuShortcut -eq 1) -and !(Test-Path $StartMenuShortcut)) {
+ New-Item -ItemType Directory -Force -Path $StartMenuShortcut | Out-Null
+ Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
+ Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Open logs.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..."
+ Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..."
+ }
+ elseif ($WAUConfig.WAU_StartMenuShortcut -ne 1) {
+ Remove-Item -Path $StartMenuShortcut -Recurse -Force | Out-Null
+ }
+}
+
+Exit 0
\ No newline at end of file
diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1
index d078670..27bbbfe 100644
--- a/Winget-AutoUpdate/Winget-Upgrade.ps1
+++ b/Winget-AutoUpdate/Winget-Upgrade.ps1
@@ -14,25 +14,13 @@ $Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsS
#Run log initialisation function
Start-Init
-#Get WAU Configurations
-$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
+#Get settings and Domain/Local Policies (GPO) if activated.
+$WAUConfig = Get-WAUConfig
#Log running context and more...
if ($IsSystem) {
Write-ToLog "Running in System context"
- #Get and set Domain/Local Policies (GPO)
- $ActivateGPOManagement, $ChangedSettings = Get-Policies
- if ($ActivateGPOManagement) {
- Write-ToLog "Activated WAU GPO Management detected, comparing..."
- if ($null -ne $ChangedSettings -and $ChangedSettings -ne 0) {
- Write-ToLog "Changed settings detected and applied" "Yellow"
- }
- else {
- Write-ToLog "No Changed settings detected" "Yellow"
- }
- }
-
# Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files.
$MaxLogFiles = $WAUConfig.WAU_MaxLogFiles
if ($null -eq $MaxLogFiles) {
diff --git a/Winget-AutoUpdate/functions/Get-Policies.ps1 b/Winget-AutoUpdate/functions/Get-Policies.ps1
deleted file mode 100644
index 0200341..0000000
--- a/Winget-AutoUpdate/functions/Get-Policies.ps1
+++ /dev/null
@@ -1,364 +0,0 @@
-#Function to get the Domain/Local Policies (GPO)
-
-Function Get-Policies {
- #Get WAU Policies and set the Configurations Registry Accordingly
- $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue
- if ($WAUPolicies) {
- if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
- $ChangedSettings = 0
- $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- if ($null -ne $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUPolicies.WAU_BypassListForUsers) -ne $($WAUConfig.WAU_BypassListForUsers))) {
- New-ItemProperty $regPath -Name WAU_BypassListForUsers -Value $($WAUPolicies.WAU_BypassListForUsers) -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_BypassListForUsers) -and ($($WAUConfig.WAU_BypassListForUsers) -or $($WAUConfig.WAU_BypassListForUsers) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_BypassListForUsers -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUPolicies.WAU_DisableAutoUpdate) -ne $($WAUConfig.WAU_DisableAutoUpdate))) {
- New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value $($WAUPolicies.WAU_DisableAutoUpdate) -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_DisableAutoUpdate) -and ($($WAUConfig.WAU_DisableAutoUpdate) -or $($WAUConfig.WAU_DisableAutoUpdate) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_DoNotRunOnMetered) -and ($($WAUPolicies.WAU_DoNotRunOnMetered) -ne $($WAUConfig.WAU_DoNotRunOnMetered))) {
- New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value $($WAUPolicies.WAU_DoNotRunOnMetered) -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_DoNotRunOnMetered) -and !$($WAUConfig.WAU_DoNotRunOnMetered)) {
- New-ItemProperty $regPath -Name WAU_DoNotRunOnMetered -Value 1 -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UpdatePrerelease) -and ($($WAUPolicies.WAU_UpdatePrerelease) -ne $($WAUConfig.WAU_UpdatePrerelease))) {
- New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value $($WAUPolicies.WAU_UpdatePrerelease) -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UpdatePrerelease) -and $($WAUConfig.WAU_UpdatePrerelease)) {
- New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUPolicies.WAU_UseWhiteList) -ne $($WAUConfig.WAU_UseWhiteList))) {
- New-ItemProperty $regPath -Name WAU_UseWhiteList -Value $($WAUPolicies.WAU_UseWhiteList) -PropertyType DWord -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UseWhiteList) -and ($($WAUConfig.WAU_UseWhiteList) -or $($WAUConfig.WAU_UseWhiteList) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_UseWhiteList -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_ListPath) -and ($($WAUPolicies.WAU_ListPath) -ne $($WAUConfig.WAU_ListPath))) {
- New-ItemProperty $regPath -Name WAU_ListPath -Value $($WAUPolicies.WAU_ListPath.TrimEnd(" ", "\", "/")) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_ListPath) -and $($WAUConfig.WAU_ListPath)) {
- Remove-ItemProperty $regPath -Name WAU_ListPath -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_ModsPath) -and ($($WAUPolicies.WAU_ModsPath) -ne $($WAUConfig.WAU_ModsPath))) {
- New-ItemProperty $regPath -Name WAU_ModsPath -Value $($WAUPolicies.WAU_ModsPath.TrimEnd(" ", "\", "/")) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_ModsPath) -and $($WAUConfig.WAU_ModsPath)) {
- Remove-ItemProperty $regPath -Name WAU_ModsPath -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
- if ($null -ne $($WAUPolicies.WAU_AzureBlobSASURL) -and ($($WAUPolicies.WAU_AzureBlobSASURL) -ne $($WAUConfig.WAU_AzureBlobSASURL))) {
- New-ItemProperty $regPath -Name WAU_AzureBlobSASURL -Value $($WAUPolicies.WAU_AzureBlobSASURL.TrimEnd(" ", "\", "/")) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_AzureBlobSASURL) -and $($WAUConfig.WAU_AzureBlobSASURL)) {
- Remove-ItemProperty $regPath -Name WAU_AzureBlobSASURL -Force -ErrorAction SilentlyContinue | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_NotificationLevel) -and ($($WAUPolicies.WAU_NotificationLevel) -ne $($WAUConfig.WAU_NotificationLevel))) {
- New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $($WAUPolicies.WAU_NotificationLevel) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_NotificationLevel) -and $($WAUConfig.WAU_NotificationLevel) -ne "Full") {
- New-ItemProperty $regPath -Name WAU_NotificationLevel -Value "Full" -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UpdatesAtTime) -and ($($WAUPolicies.WAU_UpdatesAtTime) -ne $($WAUConfig.WAU_UpdatesAtTime))) {
- New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $($WAUPolicies.WAU_UpdatesAtTime) -Force | Out-Null
- $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
- $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0, 11)
- $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19, 6)
- $Boundary = $PreStartBoundary + $($WAUPolicies.WAU_UpdatesAtTime) + $PostStartBoundary
- $definition.Triggers.Item($triggerId).StartBoundary = $Boundary
- break
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtTime) -and $($WAUConfig.WAU_UpdatesAtTime) -ne "06:00:00") {
- New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value "06:00:00" -Force | Out-Null
- $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
- $PreStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(0, 11)
- $PostStartBoundary = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(19, 6)
- $Boundary = $PreStartBoundary + "06:00:00" + $PostStartBoundary
- $definition.Triggers.Item($triggerId).StartBoundary = $Boundary
- break
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.WAU_UpdatesInterval))) {
- New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
- $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11, 8)
- $definition.Triggers.Remove($triggerId)
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
-
- if (!$($WAUConfig.WAU_UpdatesAtTime)) {
- New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null
- $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- }
-
- if ($($WAUPolicies.WAU_UpdatesInterval) -ne "Never") {
- #Count Triggers (correctly)
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- $definition.Triggers.Count | Out-Null
- switch ($($WAUPolicies.WAU_UpdatesInterval)) {
- "Daily" { $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime); break }
- "BiDaily" { $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime) -DaysInterval 2; break }
- "Weekly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2; break }
- "BiWeekly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 2; break }
- "Monthly" { $tasktrigger = New-ScheduledTaskTrigger -Weekly -At $($WAUConfig.WAU_UpdatesAtTime) -DaysOfWeek 2 -WeeksInterval 4; break }
- }
- if ($definition.Triggers.Count -gt 0) {
- $triggers = @()
- $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers
- $triggers += $tasktrigger
- Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers
- }
- else {
- Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger
- }
- }
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "Daily") {
- New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "Daily" -Force | Out-Null
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if (($definition.Triggers.Item($triggerId).Type -eq "2") -or ($definition.Triggers.Item($triggerId).Type -eq "3")) {
- $UpdatesAtTime = ($definition.Triggers.Item($triggerId).StartBoundary).Substring(11, 8)
- $definition.Triggers.Remove($triggerId)
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
-
- if (!$($WAUConfig.WAU_UpdatesAtTime)) {
- New-ItemProperty $regPath -Name WAU_UpdatesAtTime -Value $UpdatesAtTime -Force | Out-Null
- $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- }
-
- $tasktrigger = New-ScheduledTaskTrigger -Daily -At $($WAUConfig.WAU_UpdatesAtTime)
-
- #Count Triggers (correctly)
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- $definition.Triggers.Count | Out-Null
- if ($definition.Triggers.Count -gt 0) {
- $triggers = @()
- $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers
- $triggers += $tasktrigger
- Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers
- }
- else {
- Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger
- }
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUPolicies.WAU_UpdatesAtLogon) -ne $($WAUConfig.WAU_UpdatesAtLogon))) {
- if ($WAUPolicies.WAU_UpdatesAtLogon -eq 1) {
- New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value $($WAUPolicies.WAU_UpdatesAtLogon) -PropertyType DWord -Force | Out-Null
- $triggers = @()
- $triggers += (Get-ScheduledTask "Winget-AutoUpdate").Triggers
- #Count Triggers (correctly)
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- $triggerLogon = $false
- foreach ($trigger in $definition.Triggers) {
- if ($trigger.Type -eq "9") {
- $triggerLogon = $true
- break
- }
- }
- if (!$triggerLogon) {
- $triggers += New-ScheduledTaskTrigger -AtLogon
- Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $triggers
- }
- }
- else {
- New-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Value $($WAUPolicies.WAU_UpdatesAtLogon) -PropertyType DWord -Force | Out-Null
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- $definition.Triggers.Count | Out-Null
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if ($definition.Triggers.Item($triggerId).Type -eq "9") {
- $definition.Triggers.Remove($triggerId)
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
- }
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UpdatesAtLogon) -and ($($WAUConfig.WAU_UpdatesAtLogon) -or $($WAUConfig.WAU_UpdatesAtLogon) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_UpdatesAtLogon -Force -ErrorAction SilentlyContinue | Out-Null
- $service = New-Object -ComObject Schedule.Service
- $service.Connect($env:COMPUTERNAME)
- $folder = $service.GetFolder('\')
- $task = $folder.GetTask("Winget-AutoUpdate")
- $definition = $task.Definition
- for ($triggerId = 1; $triggerId -le $definition.Triggers.Count; $triggerId++) {
- if ($definition.Triggers.Item($triggerId).Type -eq "9") {
- $definition.Triggers.Remove($triggerId)
- $triggerId -= 1
- }
- }
- $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_UserContext) -and ($($WAUPolicies.WAU_UserContext) -ne $($WAUConfig.WAU_UserContext))) {
- New-ItemProperty $regPath -Name WAU_UserContext -Value $($WAUPolicies.WAU_UserContext) -PropertyType DWord -Force | Out-Null
- if ($WAUPolicies.WAU_UserContext -eq 1) {
- # Settings for the scheduled task in User context
- $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\winget-upgrade.ps1`"`""
- $taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
- $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
-
- # Set up the task for user apps
- $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
- Register-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -InputObject $task -Force
- }
- else {
- Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
- }
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_UserContext) -and ($($WAUConfig.WAU_UserContext) -or $($WAUConfig.WAU_UserContext) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_UserContext -Force -ErrorAction SilentlyContinue | Out-Null
- Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_DesktopShortcut) -and ($($WAUPolicies.WAU_DesktopShortcut) -ne $($WAUConfig.WAU_DesktopShortcut))) {
- New-ItemProperty $regPath -Name WAU_DesktopShortcut -Value $($WAUPolicies.WAU_DesktopShortcut) -PropertyType DWord -Force | Out-Null
- if ($WAUPolicies.WAU_DesktopShortcut -eq 1) {
- Add-Shortcut "wscript.exe" "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
- }
- else {
- Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null
- }
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_DesktopShortcut) -and ($($WAUConfig.WAU_DesktopShortcut) -or $($WAUConfig.WAU_DesktopShortcut) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_DesktopShortcut -Force -ErrorAction SilentlyContinue | Out-Null
- Remove-Item -Path "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_StartMenuShortcut) -and ($($WAUPolicies.WAU_StartMenuShortcut) -ne $($WAUConfig.WAU_StartMenuShortcut))) {
- New-ItemProperty $regPath -Name WAU_StartMenuShortcut -Value $($WAUPolicies.WAU_StartMenuShortcut) -PropertyType DWord -Force | Out-Null
- if ($WAUPolicies.WAU_StartMenuShortcut -eq 1) {
- if (!(Test-Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)")) {
- New-Item -ItemType Directory -Force -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" | Out-Null
- }
- Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Check for updated Apps.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
- Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Open logs.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Logs`"" "${env:SystemRoot}\System32\shell32.dll,-16763" "Open existing WAU logs..."
- Add-Shortcut "wscript.exe" "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..."
- }
- else {
- Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null
- }
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_StartMenuShortcut) -and ($($WAUConfig.WAU_StartMenuShortcut) -or $($WAUConfig.WAU_StartMenuShortcut) -eq 0)) {
- Remove-ItemProperty $regPath -Name WAU_StartMenuShortcut -Force -ErrorAction SilentlyContinue | Out-Null
- Remove-Item -Path "${env:ProgramData}\Microsoft\Windows\Start Menu\Programs\Winget-AutoUpdate (WAU)" -Recurse -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_MaxLogFiles) -and ($($WAUPolicies.WAU_MaxLogFiles) -ne $($WAUConfig.WAU_MaxLogFiles))) {
- New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $($WAUPolicies.WAU_MaxLogFiles.TrimEnd(" ", "\", "/")) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_MaxLogFiles) -and $($WAUConfig.WAU_MaxLogFiles) -ne 3) {
- New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value 3 -Force | Out-Null
- $ChangedSettings++
- }
-
- if ($null -ne $($WAUPolicies.WAU_MaxLogSize) -and ($($WAUPolicies.WAU_MaxLogSize) -ne $($WAUConfig.WAU_MaxLogSize))) {
- New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $($WAUPolicies.WAU_MaxLogSize.TrimEnd(" ", "\", "/")) -Force | Out-Null
- $ChangedSettings++
- }
- elseif ($null -eq $($WAUPolicies.WAU_MaxLogSize) -and $($WAUConfig.WAU_MaxLogSize) -ne 1048576) {
- New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -Force | Out-Null
- $ChangedSettings++
- }
-
- #Get WAU Configurations after Policies change
- $Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
- }
- }
- Return $($WAUPolicies.WAU_ActivateGPOManagement), $ChangedSettings
-}
diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
new file mode 100644
index 0000000..4bf1238
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
@@ -0,0 +1,26 @@
+#Function to get the WAU settings, including Domain/Local Policies (GPO)
+
+Function Get-WAUConfig {
+
+ #Get WAU Configurations
+ $WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -ErrorAction SilentlyContinue
+
+ #Get WAU Policies
+ $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue
+
+ #If WAU Policies detected, apply settings
+ if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
+
+ Write-ToLog "WAU Policies management activated."
+
+ #Replace loaded configurations by ones from Policies in 'WAUConfig'
+ $WAUPolicies.PSObject.Properties | ForEach-Object {
+ $WAUConfig.PSObject.Properties.add($_)
+ }
+
+ #Add tag to activate WAU-Policies
+ New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_ManagementTag -Value 1 -Force | Out-Null
+ }
+
+ return $WAUConfig
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
index 8457249..d21cff4 100644
--- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
+++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
@@ -174,6 +174,7 @@ function Invoke-PostUpdateActions {
#Remove old functions / files
$FileNames = @(
+ "$WorkingDir\functions\Get-Policies.ps1",
"$WorkingDir\functions\Get-WAUConfig.ps1",
"$WorkingDir\functions\Get-WAUCurrentVersion.ps1",
"$WorkingDir\functions\Get-WAUUpdateStatus.ps1",
From 00d73ac23317251572e1b64ad96738054328f2a4 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 01:20:35 +0200
Subject: [PATCH 02/14] Added uninstalls
---
Winget-AutoUpdate-Install.ps1 | 1 +
Winget-AutoUpdate/WAU-Uninstall.ps1 | 1 +
2 files changed, 2 insertions(+)
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index cd0da78..3e89f95 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -548,6 +548,7 @@ function Uninstall-WingetAutoUpdate {
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
+ Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
diff --git a/Winget-AutoUpdate/WAU-Uninstall.ps1 b/Winget-AutoUpdate/WAU-Uninstall.ps1
index ff10d8d..5003189 100644
--- a/Winget-AutoUpdate/WAU-Uninstall.ps1
+++ b/Winget-AutoUpdate/WAU-Uninstall.ps1
@@ -50,6 +50,7 @@ try {
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-UserContext" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
+ Get-ScheduledTask -TaskName "Winget-AutoUpdate-Policies" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
& reg delete "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /f | Out-Null
& reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" /f | Out-Null
if (Test-Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate") {
From 38ecb6f6c1324ef1c1b5364c21498a272b47b425 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 10:29:17 +0200
Subject: [PATCH 03/14] Log latest applied settings
---
Winget-AutoUpdate/WAU-Policies.ps1 | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1
index 3632b0b..d942510 100644
--- a/Winget-AutoUpdate/WAU-Policies.ps1
+++ b/Winget-AutoUpdate/WAU-Policies.ps1
@@ -60,6 +60,12 @@ if ($WAUConfig.WAU_ManagementTag -eq 1) {
elseif ($WAUConfig.WAU_StartMenuShortcut -ne 1) {
Remove-Item -Path $StartMenuShortcut -Recurse -Force | Out-Null
}
+
+ #Log latest applied config
+ $GPOLogFile = "$($WAUConfig.InstallLocation)\logs\LatestAppliedSettings.txt"
+ Set-Content -Path $GPOLogFile -Value "### POLICY CYCLE - $(Get-Date) ###"
+ $WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -FilePath $GPOLogFile -Append
+
}
Exit 0
\ No newline at end of file
From 58d2cb14ffa37b31f96101af249d6f36ebd3f259 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 17:30:34 +0200
Subject: [PATCH 04/14] Fix scheduled task
---
README.md | 6 +++---
Winget-AutoUpdate-Install.ps1 | 2 ++
Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +-
Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 | 3 +--
4 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/README.md b/README.md
index 45437dc..e86aca7 100644
--- a/README.md
+++ b/README.md
@@ -172,8 +172,8 @@ Remove scheduled tasks and scripts.
See https://github.com/Romanitho/Winget-AutoUpdate/discussions/88
## Custom script (Mods for WAU)
-**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.
-This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.
+**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.
+This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.
If **ExitCode** is **1** from `_WAU-mods.ps1` then **Re-run WAU**.
## Custom scripts (Mods feature for Apps)
From version 1.8.0, the Mods feature allows you to run additional scripts when upgrading or installing an app.
@@ -206,7 +206,7 @@ This will use the **content** of the text file as a native **winget --override**
In an enterprise environment it's crucial that different groups can have different settings in applications etc. or to implement other mandatory settings, i.e for security/management reasons.
**WAU** doesn't have any setting that can be changed except for when installing (or editing the registry/the task `Winget-AutoUpdate` as **Admin**).
With the use of **ADML/ADMX** files you can manage every **WAU** setting from within **GPO**.
-They will be detected/evaluated during the next run of **WAU** (taking effect before any actions).
+They will be detected/evaluated on a daily basis.
The **GPO ADMX/ADML** validated with: [Windows 10 - Validate ADMX for Ingestion](https://developer.vmware.com/samples/7115/windows-10---validate-admx-for-ingestion)
Read more in the `README.md` under the directory **Policies**.
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index 3e89f95..e21a20c 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -401,10 +401,12 @@ function Install-WingetAutoUpdate {
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
+ # Settings for the GPO scheduled task
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\WAU-Policies.ps1`""
$tasktrigger = New-ScheduledTaskTrigger -Daily -At 6am
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
+ # Set up the task, and register it
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Policies' -TaskPath 'WAU' -InputObject $task -Force | Out-Null
diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1
index 27bbbfe..ac03bc4 100644
--- a/Winget-AutoUpdate/Winget-Upgrade.ps1
+++ b/Winget-AutoUpdate/Winget-Upgrade.ps1
@@ -303,7 +303,7 @@ if (Test-Network) {
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -ErrorAction SilentlyContinue
if (!$UserContextTask) {
#Create the scheduled task in User context
- $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-upgrade.ps1`"`""
+ $taskAction = New-ScheduledTaskAction -Execute "wscript.exe" -Argument "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\winget-upgrade.ps1`"`""
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
index 4841740..cd2e3c6 100644
--- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
+++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1
@@ -180,7 +180,6 @@ function Invoke-PostUpdateActions {
#Remove old functions / files
$FileNames = @(
"$WorkingDir\functions\Get-Policies.ps1",
- "$WorkingDir\functions\Get-WAUConfig.ps1",
"$WorkingDir\functions\Get-WAUCurrentVersion.ps1",
"$WorkingDir\functions\Get-WAUUpdateStatus.ps1",
"$WorkingDir\functions\Write-Log.ps1",
@@ -210,7 +209,7 @@ function Invoke-PostUpdateActions {
$UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath '\' -ErrorAction SilentlyContinue
if ($UserContextTask) {
#Remove Winget-AutoUpdate-UserContext at root.
- Unregister-ScheduledTask $UserContextTask -Confirm:$False
+ $null = $UserContextTask | Unregister-ScheduledTask -Confirm:$False
#Set it in registry as activated.
New-ItemProperty $regPath -Name WAU_UserContext -Value 1 -PropertyType DWord -Force | Out-Null
From be4e0bcc75b4c75c885ea653a3af25a790f7a8b8 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 17:31:30 +0200
Subject: [PATCH 05/14] Rename Policies/WAU.admx to Policies/ADMX/WAU.admx
---
Policies/{ => ADMX}/WAU.admx | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename Policies/{ => ADMX}/WAU.admx (100%)
diff --git a/Policies/WAU.admx b/Policies/ADMX/WAU.admx
similarity index 100%
rename from Policies/WAU.admx
rename to Policies/ADMX/WAU.admx
From dca2f6f085676ea46e8f56b1a02f27fb198a1ee2 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 17:32:12 +0200
Subject: [PATCH 06/14] Rename Policies/en-US/WAU.adml to
Policies/ADMX/en-US/WAU.adml
---
Policies/{ => ADMX}/en-US/WAU.adml | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename Policies/{ => ADMX}/en-US/WAU.adml (100%)
diff --git a/Policies/en-US/WAU.adml b/Policies/ADMX/en-US/WAU.adml
similarity index 100%
rename from Policies/en-US/WAU.adml
rename to Policies/ADMX/en-US/WAU.adml
From a47dd0ea929c31d12a56c708b950d761ed15e91a Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 10 Oct 2023 18:10:45 +0200
Subject: [PATCH 07/14] Add ADMX in release
---
.github/workflows/WAU-AutoCreatePreVersion.yml | 15 +++++++++------
.github/workflows/WAU-CreateNewVersion.yml | 15 +++++++++------
2 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/.github/workflows/WAU-AutoCreatePreVersion.yml b/.github/workflows/WAU-AutoCreatePreVersion.yml
index 32d3f95..3424177 100644
--- a/.github/workflows/WAU-AutoCreatePreVersion.yml
+++ b/.github/workflows/WAU-AutoCreatePreVersion.yml
@@ -82,11 +82,14 @@ jobs:
- name: Build project
run: |
- zip -r WAU Winget-AutoUpdate/*
- zip -r WAU Winget-AutoUpdate-Install.ps1
- zip -r WAU excluded_apps.txt
- zip -r WAU install.bat
- zip -r WAU uninstall.bat
+ zip -r WAU.zip Winget-AutoUpdate
+ zip WAU.zip Winget-AutoUpdate-Install.ps1
+ zip WAU.zip excluded_apps.txt
+ zip WAU.zip install.bat
+ zip WAU.zip uninstall.bat
+ cd Policies
+ zip -r ../WAU_ADMX.zip *
+ cd ..
- name: Create release
uses: "ncipollo/release-action@v1"
@@ -96,7 +99,7 @@ jobs:
prerelease: true
generateReleaseNotes: true
name: "v${{ steps.versioning.outputs.version }} [Nightly Build]"
- artifacts: "WAU.zip"
+ artifacts: "WAU.zip,WAU_ADMX.zip"
- name: URL to release
run: echo "Release -> ${{ steps.release.outputs.html_url }}"
diff --git a/.github/workflows/WAU-CreateNewVersion.yml b/.github/workflows/WAU-CreateNewVersion.yml
index 9abb2ea..dc0facc 100644
--- a/.github/workflows/WAU-CreateNewVersion.yml
+++ b/.github/workflows/WAU-CreateNewVersion.yml
@@ -55,11 +55,14 @@ jobs:
- name: Build project
run: |
- zip -r WAU Winget-AutoUpdate/*
- zip -r WAU Winget-AutoUpdate-Install.ps1
- zip -r WAU excluded_apps.txt
- zip -r WAU install.bat
- zip -r WAU uninstall.bat
+ zip -r WAU.zip Winget-AutoUpdate
+ zip WAU.zip Winget-AutoUpdate-Install.ps1
+ zip WAU.zip excluded_apps.txt
+ zip WAU.zip install.bat
+ zip WAU.zip uninstall.bat
+ cd Policies
+ zip -r ../WAU_ADMX.zip *
+ cd ..
- name: Create release
uses: "ncipollo/release-action@v1"
@@ -68,4 +71,4 @@ jobs:
prerelease: ${{ github.event.inputs.pre-release }}
generateReleaseNotes: true
name: "v${{ steps.versioning.outputs.version }}"
- artifacts: "WAU.zip"
+ artifacts: "WAU.zip,WAU_ADMX.zip"
From 4236fc4f1228ba5583dd0f27767ca706ac6d8afe Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Wed, 11 Oct 2023 09:59:17 +0200
Subject: [PATCH 08/14] reset WAU-Polices if GPO management disabled
---
Winget-AutoUpdate/WAU-Policies.ps1 | 12 ++++++++++--
Winget-AutoUpdate/Winget-Upgrade.ps1 | 3 +++
Winget-AutoUpdate/functions/Get-WAUConfig.ps1 | 8 +++-----
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1
index d942510..5197747 100644
--- a/Winget-AutoUpdate/WAU-Policies.ps1
+++ b/Winget-AutoUpdate/WAU-Policies.ps1
@@ -13,8 +13,8 @@ Daily update settings from policies
#Get WAU settings
$WAUConfig = Get-WAUConfig
-#Check if GPO already applied at least once to this machine (ManagementTag)
-if ($WAUConfig.WAU_ManagementTag -eq 1) {
+#Check if GPO got applied from Get-WAUConfig
+if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
#Update 'Winget-AutoUpdate' scheduled task settings
$taskTriggers = @()
@@ -66,6 +66,14 @@ if ($WAUConfig.WAU_ManagementTag -eq 1) {
Set-Content -Path $GPOLogFile -Value "### POLICY CYCLE - $(Get-Date) ###"
$WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -FilePath $GPOLogFile -Append
+ #Reset WAU_RunGPOManagement if not GPO managed anymore (This is used to run this job one last time and reset initial settings)
+ if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
+ Add-Content -Path $GPOLogFile -Value "GPO Management Enabled."
+ }
+ else {
+ New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
+ Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
+ }
}
Exit 0
\ No newline at end of file
diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1
index ac03bc4..b282b0b 100644
--- a/Winget-AutoUpdate/Winget-Upgrade.ps1
+++ b/Winget-AutoUpdate/Winget-Upgrade.ps1
@@ -16,6 +16,9 @@ Start-Init
#Get settings and Domain/Local Policies (GPO) if activated.
$WAUConfig = Get-WAUConfig
+if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
+ Write-ToLog "WAU Policies management activated."
+}
#Log running context and more...
if ($IsSystem) {
diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
index 4bf1238..e3ae8dc 100644
--- a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
+++ b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
@@ -11,15 +11,13 @@ Function Get-WAUConfig {
#If WAU Policies detected, apply settings
if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
- Write-ToLog "WAU Policies management activated."
-
- #Replace loaded configurations by ones from Policies in 'WAUConfig'
+ #Replace loaded configurations by ones from Policies
$WAUPolicies.PSObject.Properties | ForEach-Object {
$WAUConfig.PSObject.Properties.add($_)
}
- #Add tag to activate WAU-Policies
- New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_ManagementTag -Value 1 -Force | Out-Null
+ #Add 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
}
return $WAUConfig
From ad40775ab3e428c665230279649f29bed2a780b6 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Wed, 11 Oct 2023 15:38:49 +0200
Subject: [PATCH 09/14] Minor change
---
Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Winget-AutoUpdate/Winget-Upgrade.ps1
index b282b0b..b40963a 100644
--- a/Winget-AutoUpdate/Winget-Upgrade.ps1
+++ b/Winget-AutoUpdate/Winget-Upgrade.ps1
@@ -17,7 +17,7 @@ Start-Init
#Get settings and Domain/Local Policies (GPO) if activated.
$WAUConfig = Get-WAUConfig
if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
- Write-ToLog "WAU Policies management activated."
+ Write-ToLog "WAU Policies management Enabled."
}
#Log running context and more...
From db16385c1787e5c78de4243b237d52fddfddf223 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Thu, 12 Oct 2023 00:53:21 +0200
Subject: [PATCH 10/14] Testing and adjustments
---
Winget-AutoUpdate/WAU-Policies.ps1 | 47 +++++++++++--------
Winget-AutoUpdate/functions/Get-WAUConfig.ps1 | 25 ++++++----
2 files changed, 43 insertions(+), 29 deletions(-)
diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1
index 5197747..cbae962 100644
--- a/Winget-AutoUpdate/WAU-Policies.ps1
+++ b/Winget-AutoUpdate/WAU-Policies.ps1
@@ -16,28 +16,45 @@ $WAUConfig = Get-WAUConfig
#Check if GPO got applied from Get-WAUConfig
if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
+ #Log init
+ $GPOLogFile = "$($WAUConfig.InstallLocation)\logs\LatestAppliedSettings.txt"
+ Set-Content -Path $GPOLogFile -Value "### POLICY CYCLE - $(Get-Date) ###`n"
+
+ #Reset WAU_RunGPOManagement if not GPO managed anymore (This is used to run this job one last time and reset initial settings)
+ if ($($WAUConfig.WAU_ActivateGPOManagement -eq 1)) {
+ Add-Content -Path $GPOLogFile -Value "GPO Management Enabled."
+ }
+ else {
+ New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
+ $WAUConfig.WAU_RunGPOManagement = 0
+ Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
+ }
+
#Update 'Winget-AutoUpdate' scheduled task settings
$taskTriggers = @()
if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) {
$tasktriggers += New-ScheduledTaskTrigger -AtLogOn
}
if ($WAUConfig.WAU_UpdatesInterval -eq "Daily") {
- $tasktriggers += New-ScheduledTaskTrigger -Daily -At $UpdatesAtTime
+ $tasktriggers += New-ScheduledTaskTrigger -Daily -At $WAUConfig.WAU_UpdatesAtTime
}
elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiDaily") {
- $tasktriggers += New-ScheduledTaskTrigger -Daily -At $UpdatesAtTime -DaysInterval 2
+ $tasktriggers += New-ScheduledTaskTrigger -Daily -At $WAUConfig.WAU_UpdatesAtTime -DaysInterval 2
}
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Weekly") {
- $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2
}
elseif ($WAUConfig.WAU_UpdatesInterval -eq "BiWeekly") {
- $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 2
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 2
}
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") {
- $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
+ $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
}
if ($taskTriggers) {
- Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue | Set-ScheduledTask -Trigger $taskTriggers
+ #Get Winget-AutoUpdate scheduled task
+ $WAUTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue
+ #Edit scheduled task
+ Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null
}
#Update Desktop shortcut
@@ -46,7 +63,7 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
Add-Shortcut "wscript.exe" $DesktopShortcut "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`"`"" "${env:SystemRoot}\System32\shell32.dll,-16739" "Manual start of Winget-AutoUpdate (WAU)..."
}
elseif ($WAUConfig.WAU_DesktopShortcut -ne 1) {
- Remove-Item -Path $DesktopShortcut -Force | Out-Null
+ Remove-Item -Path $DesktopShortcut -Force -ErrorAction SilentlyContinue | Out-Null
}
#Update Start Menu shortcuts
@@ -58,22 +75,12 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
Add-Shortcut "wscript.exe" "$StartMenuShortcut\WAU - Web Help.lnk" "`"$($WAUConfig.InstallLocation)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WAUConfig.InstallLocation)\user-run.ps1`" -Help`"" "${env:SystemRoot}\System32\shell32.dll,-24" "Help for WAU..."
}
elseif ($WAUConfig.WAU_StartMenuShortcut -ne 1) {
- Remove-Item -Path $StartMenuShortcut -Recurse -Force | Out-Null
+ Remove-Item -Path $StartMenuShortcut -Recurse -Force -ErrorAction SilentlyContinue | Out-Null
}
#Log latest applied config
- $GPOLogFile = "$($WAUConfig.InstallLocation)\logs\LatestAppliedSettings.txt"
- Set-Content -Path $GPOLogFile -Value "### POLICY CYCLE - $(Get-Date) ###"
- $WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -FilePath $GPOLogFile -Append
-
- #Reset WAU_RunGPOManagement if not GPO managed anymore (This is used to run this job one last time and reset initial settings)
- if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
- Add-Content -Path $GPOLogFile -Value "GPO Management Enabled."
- }
- else {
- New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
- Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
- }
+ Add-Content -Path $GPOLogFile -Value "`nLatest applied settings:"
+ $WAUConfig.PSObject.Properties | Where-Object { $_.Name -like "WAU_*" } | Select-Object Name, Value | Out-File -Encoding default -FilePath $GPOLogFile -Append
}
Exit 0
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
index e3ae8dc..ab5fa51 100644
--- a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
+++ b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1
@@ -2,23 +2,30 @@
Function Get-WAUConfig {
- #Get WAU Configurations
+ #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
- #Get WAU Policies
- $WAUPolicies = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -ErrorAction SilentlyContinue
-
- #If WAU Policies detected, apply settings
- if ($($WAUPolicies.WAU_ActivateGPOManagement -eq 1)) {
+ #If GPO Management is enabled, replace settings
+ if ($ActivateGPOManagement -eq 1) {
#Replace loaded configurations by ones from Policies
$WAUPolicies.PSObject.Properties | ForEach-Object {
$WAUConfig.PSObject.Properties.add($_)
}
-
- #Add 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
}
+ #Return config
return $WAUConfig
}
\ No newline at end of file
From af65eb63924dfe16eb6491f9c25a1127361a1066 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Thu, 12 Oct 2023 01:01:33 +0200
Subject: [PATCH 11/14] Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e86aca7..5f362da 100644
--- a/README.md
+++ b/README.md
@@ -172,8 +172,8 @@ Remove scheduled tasks and scripts.
See https://github.com/Romanitho/Winget-AutoUpdate/discussions/88
## Custom script (Mods for WAU)
-**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.
-This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.
+**Mods for WAU** allows you to craft a script to do whatever you like via `_WAU-mods.ps1` in the **mods** folder.
+This script executes **if the network is active/any version of Winget is installed/WAU is running as SYSTEM**.
If **ExitCode** is **1** from `_WAU-mods.ps1` then **Re-run WAU**.
## Custom scripts (Mods feature for Apps)
From version 1.8.0, the Mods feature allows you to run additional scripts when upgrading or installing an app.
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 12/14] 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
From 08a9a99be8c32022bff3c642b052621eb42116e8 Mon Sep 17 00:00:00 2001
From: romanitho <96626929+Romanitho@users.noreply.github.com>
Date: Thu, 12 Oct 2023 23:34:55 +0200
Subject: [PATCH 13/14] fix no trigger set (only manual run)
---
Winget-AutoUpdate/WAU-Policies.ps1 | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/Winget-AutoUpdate/WAU-Policies.ps1 b/Winget-AutoUpdate/WAU-Policies.ps1
index e3eb61c..da104c9 100644
--- a/Winget-AutoUpdate/WAU-Policies.ps1
+++ b/Winget-AutoUpdate/WAU-Policies.ps1
@@ -13,7 +13,7 @@ Daily update settings from policies
#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
+ #Add (or update) tag to activate WAU-Policies Management
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 1 -Force | Out-Null
}
@@ -29,7 +29,7 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
#Reset WAU_RunGPOManagement if not GPO managed anymore (This is used to run this job one last time and reset initial settings)
if ($($WAUConfig.WAU_ActivateGPOManagement -eq 1)) {
- Add-Content -Path $GPOLogFile -Value "GPO Management Enabled."
+ Add-Content -Path $GPOLogFile -Value "GPO Management Enabled. Policies updated."
}
else {
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null
@@ -37,6 +37,9 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
Add-Content -Path $GPOLogFile -Value "GPO Management Disabled. Policies removed."
}
+ #Get Winget-AutoUpdate scheduled task
+ $WAUTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue
+
#Update 'Winget-AutoUpdate' scheduled task settings
$taskTriggers = @()
if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) {
@@ -57,12 +60,17 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") {
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
}
+ #If trigger(s) set
if ($taskTriggers) {
- #Get Winget-AutoUpdate scheduled task
- $WAUTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue
#Edit scheduled task
Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null
}
+ #If not, remove trigger(s)
+ else {
+ #Remove by setting past due date
+ $tasktriggers = New-ScheduledTaskTrigger -Once -At "01/01/1970"
+ Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null
+ }
#Update Desktop shortcut
$DesktopShortcut = "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"
From abef81181f492027a2f5cce911ca652676decb36 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
Date: Fri, 13 Oct 2023 01:07:46 +0000
Subject: [PATCH 14/14] Changed version to 1.17.9-1
---
Winget-AutoUpdate/Version.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/Version.txt b/Winget-AutoUpdate/Version.txt
index 9944cc2..6247ac3 100644
--- a/Winget-AutoUpdate/Version.txt
+++ b/Winget-AutoUpdate/Version.txt
@@ -1 +1 @@
-1.17.9-0
\ No newline at end of file
+1.17.9-1
\ No newline at end of file