MS Teams Notification hinzugefügt

This commit is contained in:
Patrick Asmus
2026-07-06 08:05:44 +02:00
parent d1c53db1e0
commit 9fde6a896c
3 changed files with 139 additions and 5 deletions

View File

@@ -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.0.1
Datum: 05.07.2026
Modifiaktione: Logging optimiert
Version: 2.1.0
Datum: 06.07.2026
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 {
param(
[string]$Subject,
@@ -474,9 +557,10 @@ function Send-Notification {
$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
$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"
if (-not $ntfyEnabled -and -not $emailEnabled) {
if (-not $ntfyEnabled -and -not $emailEnabled -and -not $teamsEnabled) {
return
}
@@ -488,6 +572,10 @@ function Send-Notification {
if ($emailEnabled) {
Send-EmailNotification -Subject $Subject -Body $Body -UpdateResults $UpdateResults
}
if ($teamsEnabled) {
Send-TeamsNotification -Title $Subject -Body $Body -UpdateResults $UpdateResults
}
}
#endregion