Merge pull request #425 from Romanitho/GPO-fix-on-update

GPO fix
pull/428/head
Romain 2023-10-16 14:22:55 +02:00 committed by GitHub
commit 60d1e027b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -183,6 +183,18 @@ function Invoke-PostUpdateActions {
Write-ToLog "-> Old User Context task deleted and set to 'enabled' in registry." 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 ### ### End of post update actions ###