From 87365a1f498fd2d948dd3fe8694f7642ab72b181 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Mon, 16 Oct 2023 12:13:54 +0200 Subject: [PATCH] GPO fix --- .../functions/Invoke-PostUpdateActions.ps1 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 02d236e..f040f5a 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -183,6 +183,18 @@ function Invoke-PostUpdateActions { Write-ToLog "-> Old User Context task deleted and set to 'enabled' in registry." } + #Set GPO scheduled task if not existing + $GPOTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-Policies' -ErrorAction SilentlyContinue + if ($GPOTask) { + $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 + Write-ToLog "-> Policies task created." + } ### End of post update actions ###