From 862e353ed988d30cd4a21aa3da57f9ab02f82104 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sat, 30 Apr 2022 12:00:39 +0200 Subject: [PATCH 1/2] Added Update frequency option --- Winget-AutoUpdate-Install.ps1 | 33 +++++++++++++++++++++++++++++---- install.bat | 2 +- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 50cacd8..1e95d81 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -28,12 +28,21 @@ Remove scheduled tasks and scripts. .PARAMETER NotificationLevel Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). +.PARAMETER UpdatesAtLogon +Set WAU to run at user logon. + +.PARAMETER UpdatesInterval +Specify the update frequency: Daily (Default), Weekly, Biweekly or Monthly. + .EXAMPLE .\winget-install-and-update.ps1 -Silent -DoNotUpdate .EXAMPLE .\winget-install-and-update.ps1 -Silent -UseWhiteList +.EXAMPLE +.\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly + #> [CmdletBinding()] @@ -44,7 +53,9 @@ param( [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory=$False)] [Switch] $Uninstall = $false, [Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false, - [Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [String] $NotificationLevel = "Full" + [Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [String] $NotificationLevel = "Full", + [Parameter(Mandatory=$False)] [Switch] $UpdatesAtLogon = $false, + [Parameter(Mandatory=$False)] [ValidateSet("Daily","Weekly","BiWeekly","Monthly")] [String] $UpdatesInterval = "Daily" ) @@ -170,13 +181,27 @@ function Install-WingetAutoUpdate{ # Settings for the scheduled task for Updates $taskAction = New-ScheduledTaskAction –Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`"" - $taskTrigger1 = New-ScheduledTaskTrigger -AtLogOn - $taskTrigger2 = New-ScheduledTaskTrigger -Daily -At 6AM + $taskTriggers = @() + if ($UpdatesAtLogon){ + $tasktriggers += New-ScheduledTaskTrigger -AtLogOn + } + if ($UpdatesInterval -eq "Daily"){ + $tasktriggers += New-ScheduledTaskTrigger -Daily -At 6AM + } + elseif ($UpdatesInterval -eq "Weekly"){ + $tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2 + } + elseif ($UpdatesInterval -eq "BiWeekly"){ + $tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2 -WeeksInterval 2 + } + elseif ($UpdatesInterval -eq "Monthly"){ + $tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2 -WeeksInterval 4 + } $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 # Set up the task, and register it - $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger2,$taskTrigger1 + $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTriggers Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force | Out-Null # Settings for the scheduled task for Notifications diff --git a/install.bat b/install.bat index 54891cf..fe26091 100644 --- a/install.bat +++ b/install.bat @@ -1,2 +1,2 @@ @echo off -powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UpdatesAtLogon'" -Verb RunAs From 56fd5f3679f7522eced80eafe1a1dfcfad5c92d9 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sat, 30 Apr 2022 12:22:38 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 710ac4a..ea6abd5 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ Scheduled task is set to run: - At 6AM Everyday (with the -StartWhenAvailable option to be sure it is run at least once a day) This way, even without connected user, powered on computers get updated anyway. +> From version 1.9.0 (on new installations) WAU runs everyday at 6AM. You can now configure the frequency with `-UpdatesInterval` option (Daily, Weekly, Biweekly or Monthly). You can also add `-UpdatesAtLogon` parameter to run at user logon and keep this option activated like previous versions (recommanded). + ### Log location You can find logs in install location, in log folder. @@ -71,6 +73,14 @@ Use White List instead of Black List. This setting will not create the "exclude_ **-NotificationLevel** Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). + +**-UpdatesAtLogon** +Set WAU to run at user logon. + +**-UpdatesInterval** +Specify the update frequency: Daily (Default), Weekly, Biweekly or Monthly. + + **-Uninstall** Remove scheduled tasks and scripts.