Kaffeeundcode
n8n Flow-Bibliothek
n8n Workflow 01.06.2026

Flow Arbeitsbereich

Stale Device Cleanup

Flow prüfen, Nodes verstehen, JSON importieren und Credentials sauber anpassen.

Workflow Diagramm

auto-generiert
graph LR
    N0(["⚡ Weekly Schedule"])
    N1["🔧 Calculate Cutoff Date"]
    N2["🔧 Find Stale Devices"]
    N3["🔧 Generate Report"]
    N4[["📤 Send Email"]]
    N0 --> N1
    N1 --> N2
    N2 --> N3
    N3 --> N4

    classDef trigger fill:#f59e0b,stroke:#b45309,color:#000
    classDef action fill:#292524,stroke:#44403c,color:#e7e5e4
    classDef logic fill:#1e1b4b,stroke:#4338ca,color:#c7d2fe
    class N0 trigger
    class N1 action
    class N2 action
    class N3 action
    class N4 action

03_Stale_Device_Cleanup.json

{
    "name": "03_Stale_Device_Cleanup",
    "nodes": [
        {
            "parameters": {
                "rule": {
                    "interval": [
                        {
                            "field": "weeks",
                            "triggerAtHour": 9
                        }
                    ]
                }
            },
            "name": "Weekly Schedule",
            "type": "n8n-nodes-base.schedule",
            "typeVersion": 1,
            "position": [
                250,
                300
            ]
        },
        {
            "parameters": {
                "functionCode": "const date = new Date();ndate.setDate(date.getDate() - 90);nreturn [{ json: { cutoffDate: date.toISOString() } }];"
            },
            "name": "Calculate Cutoff Date",
            "type": "n8n-nodes-base.function",
            "typeVersion": 1,
            "position": [
                450,
                300
            ]
        },
        {
            "parameters": {
                "authentication": "predefinedCredentialType",
                "nodeCredentialType": "microsoftGraphOAuth2Api",
                "requestMethod": "GET",
                "url": "=https://graph.microsoft.com/v1.0/deviceManagement/managedDevices?$filter=lastSyncDateTime lt '{{ $json.cutoffDate }}'",
                "options": {}
            },
            "name": "Find Stale Devices",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 3,
            "position": [
                650,
                300
            ],
            "credentials": {
                "microsoftGraphOAuth2Api": {
                    "id": "YOUR_CREDENTIAL_ID",
                    "name": "Microsoft Graph Account"
                }
            }
        },
        {
            "parameters": {
                "functionCode": "const stale = items[0].json.value;nconst report = stale.map(d => `- ${d.deviceName} (Last Sync: ${d.lastSyncDateTime})`).join('\n');nreturn [{ json: { report, count: stale.length } }];"
            },
            "name": "Generate Report",
            "type": "n8n-nodes-base.function",
            "typeVersion": 1,
            "position": [
                850,
                300
            ]
        },
        {
            "parameters": {
                "fromEmail": "admin@yourorg.com",
                "toEmail": "it-ops@yourorg.com",
                "subject": "⚠️ Stale Intune Devices Report",
                "text": "=The following {{ $json.count }} devices have not synced in 90 days:nn{{ $json.report }}"
            },
            "name": "Send Email",
            "type": "n8n-nodes-base.emailSend",
            "typeVersion": 1,
            "position": [
                1050,
                300
            ]
        }
    ],
    "connections": {
        "Weekly Schedule": {
            "main": [
                [
                    {
                        "node": "Calculate Cutoff Date",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Calculate Cutoff Date": {
            "main": [
                [
                    {
                        "node": "Find Stale Devices",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Find Stale Devices": {
            "main": [
                [
                    {
                        "node": "Generate Report",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Generate Report": {
            "main": [
                [
                    {
                        "node": "Send Email",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    }
}