MS Teams Notification hinzugefügt
This commit is contained in:
@@ -62,6 +62,11 @@ EmailTo = admin@example.com
|
|||||||
# Send HTML formatted report with update table (true/false)
|
# Send HTML formatted report with update table (true/false)
|
||||||
EmailHtmlReport = true
|
EmailHtmlReport = true
|
||||||
|
|
||||||
|
# --- Microsoft Teams ---
|
||||||
|
TeamsEnabled = false
|
||||||
|
# Webhook URL for Microsoft Teams (Incoming Webhook connector or Workflows)
|
||||||
|
TeamsWebhookUrl =
|
||||||
|
|
||||||
[Hooks]
|
[Hooks]
|
||||||
# Path to PowerShell script to execute BEFORE updates (leave empty to disable)
|
# Path to PowerShell script to execute BEFORE updates (leave empty to disable)
|
||||||
PreUpdateScript =
|
PreUpdateScript =
|
||||||
|
|||||||
+42
-1
@@ -1,6 +1,6 @@
|
|||||||
# Benachrichtigungen einrichten
|
# Benachrichtigungen einrichten
|
||||||
|
|
||||||
Das Script unterstützt zwei unabhängige Benachrichtigungskanäle, die einzeln oder gleichzeitig genutzt werden können.
|
Das Script unterstützt drei unabhängige Benachrichtigungskanäle, die einzeln oder gleichzeitig genutzt werden können.
|
||||||
|
|
||||||
## ntfy
|
## ntfy
|
||||||
|
|
||||||
@@ -110,6 +110,47 @@ SmtpUsername =
|
|||||||
SmtpPassword =
|
SmtpPassword =
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Microsoft Teams
|
||||||
|
|
||||||
|
### Einrichtung
|
||||||
|
|
||||||
|
Benachrichtigungen werden über einen Webhook an einen Teams-Kanal gesendet. Es werden [Adaptive Cards](https://adaptivecards.io/) verwendet, die eine übersichtliche Darstellung mit Update-Details bieten.
|
||||||
|
|
||||||
|
#### Webhook erstellen (Workflows / Power Automate)
|
||||||
|
|
||||||
|
Microsoft hat den klassischen *Incoming Webhook*-Connector in Teams abgekündigt. Neue Webhooks werden über **Workflows** erstellt:
|
||||||
|
|
||||||
|
1. Im gewünschten Teams-Kanal auf **⋯** → **Workflows** klicken
|
||||||
|
2. Die Vorlage **"Post to a channel when a webhook request is received"** auswählen
|
||||||
|
3. Dem Flow einen Namen geben und bestätigen
|
||||||
|
4. Die generierte Webhook-URL kopieren
|
||||||
|
|
||||||
|
#### Webhook erstellen (klassischer Incoming Webhook-Connector)
|
||||||
|
|
||||||
|
Falls der klassische Connector in der Organisation noch verfügbar ist:
|
||||||
|
|
||||||
|
1. Im gewünschten Teams-Kanal auf **⋯** → **Connectors** klicken
|
||||||
|
2. **Incoming Webhook** suchen und **Konfigurieren** klicken
|
||||||
|
3. Namen vergeben (z.B. "Windows Updater") und optional ein Icon hochladen
|
||||||
|
4. **Erstellen** klicken und die generierte Webhook-URL kopieren
|
||||||
|
|
||||||
|
#### Config anpassen
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[Notification]
|
||||||
|
TeamsEnabled = true
|
||||||
|
TeamsWebhookUrl = https://xxxxx.webhook.office.com/webhookb2/...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Darstellung
|
||||||
|
|
||||||
|
Die Teams-Benachrichtigung wird als Adaptive Card dargestellt und enthält:
|
||||||
|
|
||||||
|
- Titel der Benachrichtigung (farblich hervorgehoben)
|
||||||
|
- Hostname und Zeitstempel
|
||||||
|
- Nachrichtentext
|
||||||
|
- Bei Update-Berichten: Detailliste aller Updates mit Status-Icons (✅ Erfolg / ❌ Fehler)
|
||||||
|
|
||||||
## Benachrichtigungs-Ereignisse
|
## Benachrichtigungs-Ereignisse
|
||||||
|
|
||||||
Das Script sendet Benachrichtigungen bei folgenden Ereignissen:
|
Das Script sendet Benachrichtigungen bei folgenden Ereignissen:
|
||||||
|
|||||||
+92
-4
@@ -9,9 +9,9 @@ Author: Patrick Asmus
|
|||||||
Web: https://www.cleveradmin.de
|
Web: https://www.cleveradmin.de
|
||||||
Repository: https://git.techniverse.net/scriptos/windows-updater.git
|
Repository: https://git.techniverse.net/scriptos/windows-updater.git
|
||||||
License: MIT
|
License: MIT
|
||||||
Version: 2.0.1
|
Version: 2.1.0
|
||||||
Datum: 05.07.2026
|
Datum: 06.07.2026
|
||||||
Modifiaktione: Logging optimiert
|
Modifiaktione: Microsoft Teams Benachrichtigungen hinzugefügt
|
||||||
#####################################################
|
#####################################################
|
||||||
#>
|
#>
|
||||||
|
|
||||||
@@ -464,6 +464,89 @@ function Send-EmailNotification {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Send-TeamsNotification {
|
||||||
|
param(
|
||||||
|
[string]$Title,
|
||||||
|
[string]$Body,
|
||||||
|
[array]$UpdateResults = @()
|
||||||
|
)
|
||||||
|
|
||||||
|
$webhookUrl = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "TeamsWebhookUrl" -Default ""
|
||||||
|
|
||||||
|
if ([string]::IsNullOrWhiteSpace($webhookUrl)) {
|
||||||
|
Write-Log "Teams webhook URL not configured, skipping Teams notification" -Level WARN
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$bodyItems = @(
|
||||||
|
@{
|
||||||
|
type = "TextBlock"
|
||||||
|
text = $Title
|
||||||
|
size = "Large"
|
||||||
|
weight = "Bolder"
|
||||||
|
color = "Accent"
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
type = "FactSet"
|
||||||
|
facts = @(
|
||||||
|
@{ title = "Host"; value = $env:COMPUTERNAME },
|
||||||
|
@{ title = "Date"; value = (Get-Date -Format "dd.MM.yyyy HH:mm:ss") }
|
||||||
|
)
|
||||||
|
},
|
||||||
|
@{
|
||||||
|
type = "TextBlock"
|
||||||
|
text = $Body
|
||||||
|
wrap = $true
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($UpdateResults.Count -gt 0) {
|
||||||
|
$bodyItems += @{
|
||||||
|
type = "TextBlock"
|
||||||
|
text = "Update Details"
|
||||||
|
weight = "Bolder"
|
||||||
|
separator = $true
|
||||||
|
spacing = "Medium"
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($r in $UpdateResults) {
|
||||||
|
$icon = if ($r.Result -match "Install|Success") { "✅" } else { "❌" }
|
||||||
|
$bodyItems += @{
|
||||||
|
type = "TextBlock"
|
||||||
|
text = "$icon **$($r.KB)** — $($r.Title) ($($r.Size)) — $($r.Result)"
|
||||||
|
wrap = $true
|
||||||
|
spacing = "Small"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$card = @{
|
||||||
|
type = "message"
|
||||||
|
attachments = @(
|
||||||
|
@{
|
||||||
|
contentType = "application/vnd.microsoft.card.adaptive"
|
||||||
|
contentUrl = $null
|
||||||
|
content = @{
|
||||||
|
'$schema' = "http://adaptivecards.io/schemas/adaptive-card.json"
|
||||||
|
type = "AdaptiveCard"
|
||||||
|
version = "1.4"
|
||||||
|
body = $bodyItems
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
$json = $card | ConvertTo-Json -Depth 10 -Compress
|
||||||
|
|
||||||
|
try {
|
||||||
|
Invoke-RestMethod -Uri $webhookUrl -Method Post -Body $json -ContentType "application/json; charset=utf-8" -ErrorAction Stop | Out-Null
|
||||||
|
Write-Log "Teams notification sent: $Title"
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Log "Failed to send Teams notification: $($_.Exception.Message)" -Level WARN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Send-Notification {
|
function Send-Notification {
|
||||||
param(
|
param(
|
||||||
[string]$Subject,
|
[string]$Subject,
|
||||||
@@ -474,9 +557,10 @@ function Send-Notification {
|
|||||||
|
|
||||||
$ntfyEnabled = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "NtfyEnabled" -Default $false -Type bool
|
$ntfyEnabled = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "NtfyEnabled" -Default $false -Type bool
|
||||||
$emailEnabled = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "EmailEnabled" -Default $false -Type bool
|
$emailEnabled = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "EmailEnabled" -Default $false -Type bool
|
||||||
|
$teamsEnabled = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "TeamsEnabled" -Default $false -Type bool
|
||||||
$ntfyPriority = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "NtfyPriority" -Default "default"
|
$ntfyPriority = Get-ConfigValue -Config $script:Config -Section "Notification" -Key "NtfyPriority" -Default "default"
|
||||||
|
|
||||||
if (-not $ntfyEnabled -and -not $emailEnabled) {
|
if (-not $ntfyEnabled -and -not $emailEnabled -and -not $teamsEnabled) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,6 +572,10 @@ function Send-Notification {
|
|||||||
if ($emailEnabled) {
|
if ($emailEnabled) {
|
||||||
Send-EmailNotification -Subject $Subject -Body $Body -UpdateResults $UpdateResults
|
Send-EmailNotification -Subject $Subject -Body $Body -UpdateResults $UpdateResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($teamsEnabled) {
|
||||||
|
Send-TeamsNotification -Title $Subject -Body $Body -UpdateResults $UpdateResults
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
Reference in New Issue
Block a user