Reviews and improvements, part 3
This commit is contained in:
@@ -159,6 +159,7 @@ Das Script sendet Benachrichtigungen bei folgenden Ereignissen. Jedes Ereignis k
|
||||
|
||||
| Ereignis | Config-Schlüssel | Priorität | Subject-Muster |
|
||||
|---|---|---|---|
|
||||
| Scan-Fehler | `NotifyOnScanError` | high | `Scan Error - <Hostname>` |
|
||||
| Modul-Fehler | `NotifyOnModuleError` | high | `Windows Update FAILED - <Hostname>` |
|
||||
| Pre-Hook fehlgeschlagen | `NotifyOnHookFailure` | high | `Windows Update ABORTED - <Hostname>` |
|
||||
| Keine Updates | `NotifyOnNoUpdates` | default | `No Updates - <Hostname>` |
|
||||
@@ -170,6 +171,14 @@ Das Script sendet Benachrichtigungen bei folgenden Ereignissen. Jedes Ereignis k
|
||||
|
||||
### Details zu jedem Ereignis
|
||||
|
||||
#### Scan-Fehler (`NotifyOnScanError`)
|
||||
|
||||
Der Windows-Update-Scan ist fehlgeschlagen (`Get-AvailableUpdates` hat `$null` zurückgegeben). Das Script bricht ab, es werden keine Updates installiert.
|
||||
|
||||
- **Priorität:** high
|
||||
- **Subject:** `Scan Error - <Hostname>`
|
||||
- **Inhalt:** Hinweis, dass der Update-Scan fehlgeschlagen ist
|
||||
|
||||
#### Modul-Fehler (`NotifyOnModuleError`)
|
||||
|
||||
Das PSWindowsUpdate-Modul konnte weder online (PSGallery) noch offline (lokaler Modules-Ordner) geladen werden. Das Script bricht ab, es werden keine Updates installiert.
|
||||
|
||||
@@ -9,9 +9,9 @@ Author: Patrick Asmus
|
||||
Web: https://www.cleveradmin.de
|
||||
Repository: https://git.techniverse.net/scriptos/windows-updater.git
|
||||
License: MIT
|
||||
Version: 2.4.0
|
||||
Version: 2.5.0
|
||||
Date: 06.07.2026
|
||||
Modifications: Change Header
|
||||
Modifications: Reviews and improvements, part 3
|
||||
#####################################################
|
||||
#>
|
||||
|
||||
@@ -412,6 +412,7 @@ function New-HtmlUpdateReport {
|
||||
}
|
||||
|
||||
function Send-EmailNotification {
|
||||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '')]
|
||||
param(
|
||||
[string]$Subject,
|
||||
[string]$Body,
|
||||
@@ -557,11 +558,11 @@ function Send-TeamsNotification {
|
||||
|
||||
function Test-NotificationEvent {
|
||||
param(
|
||||
[ValidateSet('ModuleError', 'HookFailure', 'NoUpdates', 'DryRun', 'UpdateComplete', 'Reboot', 'RebootRequired', 'ServiceRestartFailure')]
|
||||
[string]$Event
|
||||
[ValidateSet('ModuleError', 'HookFailure', 'NoUpdates', 'DryRun', 'UpdateComplete', 'Reboot', 'RebootRequired', 'ServiceRestartFailure', 'ScanError')]
|
||||
[string]$EventName
|
||||
)
|
||||
|
||||
$key = "NotifyOn$Event"
|
||||
$key = "NotifyOn$EventName"
|
||||
return Get-ConfigValue -Config $script:Config -Section "NotificationEvents" -Key $key -Default $true -Type bool
|
||||
}
|
||||
|
||||
@@ -575,7 +576,7 @@ function Send-Notification {
|
||||
)
|
||||
|
||||
if (-not [string]::IsNullOrWhiteSpace($EventName)) {
|
||||
if (-not (Test-NotificationEvent -Event $EventName)) {
|
||||
if (-not (Test-NotificationEvent -EventName $EventName)) {
|
||||
Write-Log "Notification event '$EventName' is disabled, skipping"
|
||||
return
|
||||
}
|
||||
@@ -846,7 +847,7 @@ function Install-PendingUpdates {
|
||||
if ($failed -and $retryCount -gt 0) {
|
||||
Write-Log "Retrying $(@($failed).Count) failed update(s)..." -Level WARN
|
||||
foreach ($f in $failed) {
|
||||
$kbId = if ($f.KB) { $f.KB } else { continue }
|
||||
$kbId = if ($f.KB) { $f.KB } else { $script:HasErrors = $true; continue }
|
||||
$retrySuccess = $false
|
||||
|
||||
for ($i = 1; $i -le $retryCount; $i++) {
|
||||
@@ -1019,7 +1020,7 @@ function Invoke-ScheduledReboot {
|
||||
$minute = [int]$parts[1]
|
||||
if ($hour -lt 0 -or $hour -gt 23 -or $minute -lt 0 -or $minute -gt 59) {
|
||||
Write-Log "ScheduledTime '$scheduledTime' out of range, falling back to 03:00" -Level WARN
|
||||
$hour = 3; $minute = 0
|
||||
$hour = 3; $minute = 0; $scheduledTime = "03:00"
|
||||
}
|
||||
$now = Get-Date
|
||||
$target = Get-Date -Hour $hour -Minute $minute -Second 0
|
||||
|
||||
Reference in New Issue
Block a user