Zum Inhalt
Kaffeeundcode
Skriptbibliothek
PowerShell 06.10.2026

PowerShell

Intune Discord Alert Hub

Intune-Discord-Alert-Hub.ps1

<#
.SYNOPSIS
    Intune-Discord-Alert-Hub - Pushes critical Intune events to a Discord Webhook.

.DESCRIPTION
    <!-- library-status:start -->
    Prüfstatus: Ungeprüft
    Aus dem bestehenden GitHub-Bestand übernommen; fachliche und Tenant-Abnahme ausstehend.

    <!-- library-status:end -->

    Monitors for critical state changes (e.g., VIP device non-compliance or
    high failure rates in app deployments) and sends an industrial-style
    alert to a configured Discord channel.
#>

[CmdletBinding()]
param (
    [Parameter(Mandatory=$true)]
    [string]$WebhookUrl,

    [Parameter(Mandatory=$false)]
    [string]$AlertThreshold = "10%" # Percentage of failures to trigger a fleet alert
)

process {
    Write-Host "[INFO] Checking for critical Intune events..." -ForegroundColor Cyan

    # 1. Fetch non-compliant devices (Focus on VIPs or critical group)
    $NonCompliantDevices = Get-MgDeviceManagementManagedDevice -Filter "complianceState eq 'noncompliant'" -All

    if ($NonCompliantDevices) {
        $Message = "🚨 *CRITICAL: Compliance Failure*`nTotal Non-Compliant Devices: $($NonCompliantDevices.Count)`nCheck Intune Portal for details."

        $Payload = @{
            content = $Message
            embeds = @(@{
                title = "Intune Alert Hub"
                color = 16711680 # Red
                timestamp = (Get-Date).ToString("yyyy-MM-ddTHH:mm:ssZ")
            })
        } | ConvertTo-Json

        Invoke-RestMethod -Method Post -Uri $WebhookUrl -ContentType "application/json" -Body $Payload
    }

    # 2. App Deployment Failure Check (Aggregated)
    # This is a simplified version; real implementation would iterate through all managed apps
    Write-Host "[INFO] Monitoring app deployment health..." -ForegroundColor Gray
    # ... (Logic to check failed installs across the fleet)
}