Managed Update Frequency for the Scheduler

pull/257/head
KnifMelti 2022-12-29 07:57:36 +01:00
parent 4491524378
commit 937e281ad0
3 changed files with 77 additions and 0 deletions

View File

@ -113,5 +113,43 @@
</enum> </enum>
</elements> </elements>
</policy> </policy>
<policy name="UpdatesInterval" class="Machine" displayName="$(string.UpdatesInterval)" explainText="$(string.UpdatesInterval_Explain)" key="Software\Policies\Romanitho\Winget-AutoUpdate" presentation="$(presentation.UpdatesInterval)">
<parentCategory ref="WAU"/>
<supportedOn ref="WAU:SUPPORTED_WAU_1_15_3"/>
<elements>
<enum id="UpdatesInterval" valueName="WAU_UpdatesInterval">
<item displayName="$(string.UpdatesInterval_Daily)">
<value>
<string>-Daily -At 06am</string>
</value>
</item>
<item displayName="$(string.UpdatesInterval_BiDaily)">
<value>
<string>-Daily -At 06am -DaysInterval 2</string>
</value>
</item>
<item displayName="$(string.UpdatesInterval_Weekly)">
<value>
<string>-Weekly -At 06am</string>
</value>
</item>
<item displayName="$(string.UpdatesInterval_BiWeekly)">
<value>
<string>-Weekly -At 06am -WeeksInterval 2</string>
</value>
</item>
<item displayName="$(string.UpdatesInterval_Monthly)">
<value>
<string>-Weekly -At 06am -WeeksInterval 4</string>
</value>
</item>
<item displayName="$(string.UpdatesInterval_Never)">
<value>
<string>Never</string>
</value>
</item>
</enum>
</elements>
</policy>
</policies> </policies>
</policyDefinitions> </policyDefinitions>

View File

@ -32,6 +32,22 @@ If this policy is not configured or disabled, the Default displays all notificat
<string id="NotificationLevel_Full">1. Full (Default, displays all notifications)</string> <string id="NotificationLevel_Full">1. Full (Default, displays all notifications)</string>
<string id="NotificationLevel_SuccessOnly">2. SuccessOnly (Only displays notifications for success)</string> <string id="NotificationLevel_SuccessOnly">2. SuccessOnly (Only displays notifications for success)</string>
<string id="NotificationLevel_None">3. None (Does not display any notification)</string> <string id="NotificationLevel_None">3. None (Does not display any notification)</string>
<string id="UpdatesInterval">Update Frequency</string>
<string id="UpdatesInterval_Explain">If this policy is enabled, you can configure the Update Frequency:
1. Daily (Default)
2. BiDaily
3. Weekly
4. BiWeekly
5. Monthly
6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance)
If this policy is not configured or disabled, update frequency: (1. Daily).</string>
<string id="UpdatesInterval_Daily">1. Daily (Default)</string>
<string id="UpdatesInterval_BiDaily">2. BiDaily</string>
<string id="UpdatesInterval_Weekly">3. Weekly</string>
<string id="UpdatesInterval_BiWeekly">4. BiWeekly</string>
<string id="UpdatesInterval_Monthly">5. Monthly</string>
<string id="UpdatesInterval_Never">6. Never (Can be set to 'Never' in combination with '-UpdatesAtLogon' for instance)</string>
</stringTable> </stringTable>
<presentationTable> <presentationTable>
<presentation id="ListPath"> <presentation id="ListPath">
@ -47,6 +63,9 @@ If this policy is not configured or disabled, the Default displays all notificat
<presentation id="NotificationLevel"> <presentation id="NotificationLevel">
<dropdownList refId="NotificationLevel"/> <dropdownList refId="NotificationLevel"/>
</presentation> </presentation>
<presentation id="UpdatesInterval">
<dropdownList refId="UpdatesInterval"/>
</presentation>
</presentationTable> </presentationTable>
</resources> </resources>
</policyDefinitionResources> </policyDefinitionResources>

View File

@ -99,6 +99,26 @@ if ($IsSystem) {
$ChangedSettings++ $ChangedSettings++
} }
if ($null -ne $($WAUPolicies.WAU_UpdatesInterval) -and ($($WAUPolicies.WAU_UpdatesInterval) -ne $($WAUConfig.UpdatesInterval))) {
New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value $($WAUPolicies.WAU_UpdatesInterval) -Force | Out-Null
switch ($($WAUPolicies.WAU_UpdatesInterval)) {
"-Daily -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break}
"-Daily -At 06am -DaysInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am -DaysInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break}
"-Weekly -At 06am" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break}
"-Weekly -At 06am -WeeksInterval 2" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 2; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break}
"-Weekly -At 06am -WeeksInterval 4" {$tasktrigger = New-ScheduledTaskTrigger -Weekly -At 06am -WeeksInterval 4; Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger; break}
"Never" {$service = New-Object -ComObject Schedule.Service; $service.Connect($env:COMPUTERNAME); $folder = $service.GetFolder('\'); $task = $folder.GetTask("Winget-AutoUpdate"); $definition = $task.Definition; $definition.Triggers.Remove(1); $folder.RegisterTaskDefinition($task.Name, $definition, 4, $null, $null, $null) | Out-Null; break}
default {"Something else happened"; break}
}
$ChangedSettings++
}
elseif ($null -eq $($WAUPolicies.WAU_UpdatesInterval) -and $($WAUConfig.WAU_UpdatesInterval) -ne "-Daily -At 06am") {
New-ItemProperty $regPath -Name WAU_UpdatesInterval -Value "-Daily -At 06am" -Force | Out-Null
$tasktrigger = New-ScheduledTaskTrigger -Daily -At 06am
Set-ScheduledTask -TaskName "Winget-AutoUpdate" -Trigger $tasktrigger
$ChangedSettings++
}
if ($ChangedSettings -gt 0) { if ($ChangedSettings -gt 0) {
Write-Log "Changed settings: $ChangedSettings" "Yellow" Write-Log "Changed settings: $ChangedSettings" "Yellow"
} }