Merge pull request #67 from Romanitho/Update-Frequency-Option

Added Update frequency option
pull/71/head v1.9.0
Romain 2022-04-30 12:23:26 +02:00 committed by GitHub
commit 659ff700e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 5 deletions

View File

@ -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) - 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. 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 ### Log location
You can find logs in install location, in log folder. 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** **-NotificationLevel**
Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). 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** **-Uninstall**
Remove scheduled tasks and scripts. Remove scheduled tasks and scripts.

View File

@ -28,12 +28,21 @@ Remove scheduled tasks and scripts.
.PARAMETER NotificationLevel .PARAMETER NotificationLevel
Specify the Notification level: Full (Default, displays all notification), SuccessOnly (Only displays notification for success) or None (Does not show any popup). 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 .EXAMPLE
.\winget-install-and-update.ps1 -Silent -DoNotUpdate .\winget-install-and-update.ps1 -Silent -DoNotUpdate
.EXAMPLE .EXAMPLE
.\winget-install-and-update.ps1 -Silent -UseWhiteList .\winget-install-and-update.ps1 -Silent -UseWhiteList
.EXAMPLE
.\winget-install-and-update.ps1 -Silent -UpdatesAtLogon -UpdatesInterval Weekly
#> #>
[CmdletBinding()] [CmdletBinding()]
@ -44,7 +53,9 @@ param(
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false, [Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false, [Parameter(Mandatory=$False)] [Switch] $Uninstall = $false,
[Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $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 # Settings for the scheduled task for Updates
$taskAction = New-ScheduledTaskAction Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`"" $taskAction = New-ScheduledTaskAction Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""
$taskTrigger1 = New-ScheduledTaskTrigger -AtLogOn $taskTriggers = @()
$taskTrigger2 = New-ScheduledTaskTrigger -Daily -At 6AM 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 $taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00 $taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 03:00:00
# Set up the task, and register it # 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 Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force | Out-Null
# Settings for the scheduled task for Notifications # Settings for the scheduled task for Notifications

View File

@ -1,2 +1,2 @@
@echo off @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