fix no trigger set (only manual run)

pull/418/head
romanitho 2023-10-12 23:34:55 +02:00
parent efbaa6d3e5
commit 08a9a99be8
1 changed files with 12 additions and 4 deletions

View File

@ -13,7 +13,7 @@ Daily update settings from policies
#Check if GPO Management is enabled #Check if GPO Management is enabled
$ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue $ActivateGPOManagement = Get-ItemPropertyValue "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "WAU_ActivateGPOManagement" -ErrorAction SilentlyContinue
if ($ActivateGPOManagement -eq 1) { 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 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) #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)) { 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 { else {
New-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name WAU_RunGPOManagement -Value 0 -Force | Out-Null 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." 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 #Update 'Winget-AutoUpdate' scheduled task settings
$taskTriggers = @() $taskTriggers = @()
if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) { if ($WAUConfig.WAU_UpdatesAtLogon -eq 1) {
@ -57,12 +60,17 @@ if ($WAUConfig.WAU_RunGPOManagement -eq 1) {
elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") { elseif ($WAUConfig.WAU_UpdatesInterval -eq "Monthly") {
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4 $tasktriggers += New-ScheduledTaskTrigger -Weekly -At $WAUConfig.WAU_UpdatesAtTime -DaysOfWeek 2 -WeeksInterval 4
} }
#If trigger(s) set
if ($taskTriggers) { if ($taskTriggers) {
#Get Winget-AutoUpdate scheduled task
$WAUTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate' -ErrorAction SilentlyContinue
#Edit scheduled task #Edit scheduled task
Set-ScheduledTask -TaskPath $WAUTask.TaskPath -TaskName $WAUTask.TaskName -Trigger $taskTriggers | Out-Null 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 #Update Desktop shortcut
$DesktopShortcut = "${env:Public}\Desktop\WAU - Check for updated Apps.lnk" $DesktopShortcut = "${env:Public}\Desktop\WAU - Check for updated Apps.lnk"