Automation & DevOps for M365 Automation & DevOps for M365
Tiefenreferenz zu Microsoft365DSC, Terraform AzureAD Provider, Bicep, GitHub Actions, Azure DevOps, Azure Automation, CLI for Microsoft 365, Graph Delta und Drift Detection. Deep reference for Microsoft365DSC, Terraform AzureAD provider, Bicep, GitHub Actions, Azure DevOps, Azure Automation, CLI for Microsoft 365, Graph delta, and drift detection.
Kein einzelnes Werkzeug deckt das gesamte M365-Spektrum ab. Microsoft365DSC ist stark für Konfigurationsabbildung, Terraform für deklarativen Zustand, Bicep für Azure-nahe Ressourcen, und PowerShell oder Graph bleiben für Lücken und Betriebslogik unverzichtbar. No single tool covers the whole Microsoft 365 spectrum. Microsoft365DSC is strong for configuration capture, Terraform for declarative state, Bicep for Azure-near resources, and PowerShell or Graph remain essential for gaps and operational logic.
Export, Blueprint, Drift Export, blueprint, drift
AzureAD Provider AzureAD provider
Graph und ARM Graph and ARM
OIDC und Workflows OIDC and workflows
Pipelines und Gates Pipelines and gates
Automation, Functions, Logic Apps Automation, Functions, Logic Apps
CLI for Microsoft 365 CLI for Microsoft 365
Delta, Batch, Notifications Delta, batch, notifications
Microsoft365DSC Überblick Microsoft365DSC overview
Microsoft365DSC beschreibt M365- und Entra-Konfiguration als deklaratives PowerShell-Modell. Mit Hunderten Ressourcen eignet es sich für Tenant-Export, Blueprints, Drift Detection, Assessment Mode und Deployment Mode. Microsoft365DSC describes Microsoft 365 and Entra configuration as a declarative PowerShell model. With hundreds of resources, it is suitable for tenant export, blueprints, drift detection, assessment mode, and deployment mode.
| Capability Capability | Nutzen Value | Best Practice Best practice |
|---|---|---|
| Export-M365DSCConfiguration Export-M365DSCConfiguration | Exportiert Tenant-Konfiguration in DSC-Code Exports tenant configuration into DSC code | Mit Scope und Filtern arbeiten, um den Export beherrschbar zu halten Use scope and filters to keep export manageable |
| Blueprint Blueprint | Wiederverwendbares Zielmodell für Tenants Reusable target model for tenants | Produktion und Landing Zones getrennt versionieren Version production and landing zones separately |
| Drift Detection Drift detection | Vergleicht Ist- mit Sollzustand Compares actual against desired state | Mit Governance-Prozess für Ausnahmefreigaben kombinieren Combine with a governance process for approved exceptions |
| Assessment Mode Assessment mode | Nur Vergleich, keine Änderungen Comparison only, no changes | Ideal für Brownfield-Onboarding Ideal for brownfield onboarding |
| Monitoring Mode Monitoring mode | Kontinuierliche Prüfung gegen Sollzustand Continuous verification against target state | Für kritische Sicherheitsbereiche priorisieren Prioritize for critical security areas |
| Deployment Mode Deployment mode | Erzwingt Zielkonfiguration Enforces target configuration | Nur nach Pilotierung und Rollback-Plan einsetzen Use only after piloting and with a rollback plan |
Install-Module Microsoft365DSC -Scope CurrentUser
Update-M365DSCDependencies
Connect-MgGraph -Scopes Policy.Read.All,Directory.Read.All
Export-M365DSCConfiguration -Path .\tenant-export -Components AADApplication,AADGroup,EXOTransportRule -Workloads AAD,EXO
Terraform AzureAD Provider Terraform AzureAD provider
Terraform ist stark für deklarativen Zustand, State-Management und CI/CD-gesteuerte Änderungen. Im Entra-Kontext sind Applications, Service Principals, Groups, App Role Assignments, Named Locations und Teile von Conditional Access zentrale Ressourcen. Terraform is strong for declarative state, state management, and CI/CD-driven changes. In the Entra context, applications, service principals, groups, app role assignments, named locations, and parts of Conditional Access are key resources.
| Ressource Resource | Wofür Purpose | Praxisnotiz Practical note |
|---|---|---|
| azuread_application azuread_application | App-Registrierungen App registrations | Redirect URIs, Rollen und Secrets oder Zertifikate konsequent versionieren Version redirect URIs, roles, and secrets or certificates consistently |
| azuread_service_principal azuread_service_principal | Tenant-Instanz einer Anwendung Tenant instance of an application | Besonders wichtig bei Enterprise App und Multi-Tenant-Designs Especially important for enterprise app and multitenant design |
| azuread_group azuread_group | Sicherheits- oder M365-Gruppen Security or M365 groups | Dynamische Regeln und Namensstandards berücksichtigen Consider dynamic rules and naming standards |
| azuread_conditional_access_policy azuread_conditional_access_policy | CA-Richtlinien als Code Conditional Access policies as code | Report-Only und Break-Glass-Ausnahmen immer mit modellieren Always model report-only and break-glass exceptions |
| azuread_named_location azuread_named_location | Trusted IPs oder Länder Trusted IPs or countries | Ownership für Netzwerkdaten klar definieren Define ownership for network data clearly |
| Data Sources Data sources | Lesen vorhandener Objekte für Referenzen Read existing objects for references | Hilfreich für Brownfield und Import-Szenarien Helpful for brownfield and import scenarios |
| State Management State management | Terraform State als Wahrheit über Deployments Terraform state as the truth about deployments | Remote State verschlüsseln und strikt schützen Encrypt and protect remote state strictly |
| Import Import | Bestehende Objekte in Terraform überführen Bring existing objects into Terraform | Vor dem ersten Apply sauberen Importplan erstellen Create a clean import plan before the first apply |
provider "azuread" {}
resource "azuread_application" "api" {
display_name = "contoso-api"
identifier_uris = ["api://contoso-api"]
}
resource "azuread_group" "admins" {
display_name = "Contoso-App-Admins"
security_enabled = true
}
Bicep / ARM für Entra-nahe Ressourcen Bicep / ARM for Entra-adjacent resources
Bicep ist besonders stark dort, wo Entra-Ressourcen mit Azure-Ressourcen zusammen deployt werden oder Microsoft.Graph-Typen verfügbar sind. Für reine Entra-Flächen bleibt die Abdeckung selektiv, daher ist Tool-Kombination oft sinnvoll. Bicep is particularly strong where Entra resources are deployed together with Azure resources or where Microsoft.Graph types are available. Coverage for pure Entra surface is selective, so tool combination is often the right answer.
| Bereich Area | Beispiel Example | Einsatzhinweis Usage note |
|---|---|---|
| Microsoft.Graph Bicep Types Microsoft.Graph Bicep types | Graph-nahe Objekte in deklarativer Syntax Graph-related objects in declarative syntax | API-Versionen und Supportstatus prüfen Validate API versions and support status |
| Azure + Entra Azure + Entra | Gemeinsame Deployments mit Managed Identity, RBAC, Apps Combined deployments with managed identity, RBAC, apps | Hilfreich für Landing Zones und Plattformteams Helpful for landing zones and platform teams |
| Parameter Files Parameter files | Trennung von Logik und Umgebung Separation of logic and environment | Pro Umgebung eigene Parameterdateien pflegen Maintain separate parameter files per environment |
| Deployment Stacks Deployment stacks | Lifecycle und Ownership ganzer Stacks Lifecycle and ownership of complete stacks | Gut für Plattform-Governance und Cleanup Good for platform governance and cleanup |
| Fallback to PowerShell Fallback to PowerShell | Nicht modellierte Entra-Operationen ergänzen Supplement Entra operations that are not modeled | Bicep nicht mit skriptlastigen Workarounds überfrachten Do not overload Bicep with script-heavy workarounds |
| Reviewability Reviewability | Klare Diff-Ansicht im Pull Request Clear diff view in pull requests | Gerade für Rollen- oder Policy-Änderungen wertvoll Especially valuable for role or policy changes |
resource app 'Microsoft.Graph/applications@1.0' = {
displayName: 'contoso-api'
uniqueName: 'contoso-api'
signInAudience: 'AzureADMyOrg'
}
GitHub Actions für M365 GitHub Actions for M365
GitHub Actions eignet sich hervorragend für Entra- und M365-Automation mit OIDC-Federation. Dadurch können Workflows ohne langlebige Secrets gegen Entra oder Azure authentifizieren und Richtlinien, Apps oder Gruppen sicher ändern. GitHub Actions is an excellent fit for Entra and Microsoft 365 automation with OIDC federation. That lets workflows authenticate against Entra or Azure without long-lived secrets and safely change policies, apps, or groups.
| Thema Topic | Beschreibung Description | Empfehlung Recommendation |
|---|---|---|
| Federated Credentials Federated credentials | OIDC-Vertrauen zwischen GitHub und Entra OIDC trust between GitHub and Entra | Pro Repository oder Environment granulare Vertrauensbeziehungen pflegen Maintain granular trust relationships per repository or environment |
| Service Principal Service principal | Ausführende Identität des Workflows Executing identity of the workflow | Nur nötige Graph- und Azure-Rechte vergeben Grant only required Graph and Azure rights |
| Reusable Workflows Reusable workflows | Wiederverwendbare Governance- oder Deployment-Pipelines Reusable governance or deployment pipelines | Für CA, Gruppen und App-Management standardisieren Standardize for CA, groups, and app management |
| Environment Protection Environment protection | Reviewer, Secrets, Deployment Gates Reviewers, secrets, deployment gates | Produktive Änderungen nur mit Schutzmechanismen erlauben Allow production changes only with protection mechanisms |
| Compliance Checks Compliance checks | Vor Deployment Soll-Ist-Validierung Desired-versus-actual validation before deployment | Drift Reports als Workflow-Artefakt veröffentlichen Publish drift reports as workflow artifacts |
| Common Workflows Common workflows | Deploy CA, Sync Groups, Manage Apps, Run Audits Deploy CA, sync groups, manage apps, run audits | Jeden Workflow mit idempotentem Verhalten designen Design every workflow for idempotent behavior |
name: Deploy Entra Policies
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Run Terraform
run: terraform apply -auto-approve
name: Drift Detection
on:
schedule:
- cron: '0 5 * * 1'
jobs:
drift:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- run: pwsh -File ./.github/scripts/Test-M365Drift.ps1
Azure DevOps für M365 Azure DevOps for M365
Azure DevOps Pipelines bleiben in vielen Enterprises das führende Delivery-Tool. YAML-Pipelines, Variable Groups, Key Vault Integration und Approval Gates ermöglichen auch für Entra-Änderungen kontrollierte Produktionsfreigaben. Azure DevOps pipelines remain the leading delivery tool in many enterprises. YAML pipelines, variable groups, Key Vault integration, and approval gates enable controlled production release for Entra changes as well.
| Baustein Building block | Zweck Purpose | Best Practice Best practice |
|---|---|---|
| YAML Pipeline YAML pipeline | Versionierte Delivery-Logik Versioned delivery logic | Pipelines wie Anwendungscode reviewen Review pipelines like application code |
| Variable Groups Variable groups | Geteilte Konfiguration und Parameter Shared configuration and parameters | Keine Secrets im Klartext; Key Vault oder OIDC nutzen No secrets in plain text; use Key Vault or OIDC |
| Key Vault Integration Key Vault integration | Abruf geschützter Werte zur Laufzeit Retrieve protected values at runtime | Rotation und Least Privilege beachten Respect rotation and least privilege |
| Approval Gates Approval gates | Manuelle Freigaben vor Produktion Manual approval before production | Für CA-Policies und Rollenänderungen nahezu Pflicht Almost mandatory for CA policies and role changes |
| Service Connections Service connections | Authentifizierung gegenüber Azure / Entra Authentication against Azure or Entra | OIDC oder workload identity wenn möglich bevorzugen Prefer OIDC or workload identity where possible |
| Reusable Templates Reusable templates | Einheitliche CI/CD-Bausteine Consistent CI/CD building blocks | Für Terraform, DSC und Graph-Skripte wiederverwenden Reuse for Terraform, DSC, and Graph scripts |
trigger: none
pool:
vmImage: ubuntu-latest
stages:
- stage: Validate
jobs:
- job: terraform_validate
steps:
- script: terraform init
- script: terraform plan
- stage: Deploy
approval: production
jobs:
- job: apply
steps:
- script: terraform apply -auto-approve
PowerShell Automation Patterns PowerShell automation patterns
PowerShell bleibt für M365-Automation unersetzlich, weil viele Workloads unterschiedliche Module oder Graph-Lücken haben. Azure Automation, Azure Functions und Logic Apps bilden dabei unterschiedliche Betriebsmodelle für wiederkehrende oder ereignisgetriebene Aufgaben. PowerShell remains indispensable for Microsoft 365 automation because many workloads have different modules or Graph gaps. Azure Automation, Azure Functions, and Logic Apps form different operating models for recurring or event-driven tasks.
| Plattform Platform | Einsatz Use case | Praxisnotiz Practical note |
|---|---|---|
| Azure Automation Azure Automation | Zeitgesteuerte Runbooks und Hybrid Worker Scheduled runbooks and hybrid workers | Managed Identity bevorzugen und Module zentral versionieren Prefer managed identity and version modules centrally |
| Azure Functions Azure Functions | Timer Trigger, HTTP Trigger, Durable Functions Timer trigger, HTTP trigger, durable functions | Gut für API-gesteuerte oder hochskalierende Szenarien Good for API-driven or highly scaling scenarios |
| Logic Apps Logic Apps | Connector-basierte Workflows und Freigaben Connector-based workflows and approvals | Ideal für Governance- und Approval-Prozesse Ideal for governance and approval processes |
| Hybrid Worker Hybrid worker | Lokal erreichbare Systeme oder restriktive Netzsegmente Locally reachable systems or restricted network segments | Für verbleibende On-Prem- oder ExO-Hybridabhängigkeiten nützlich Useful for remaining on-prem or ExO hybrid dependencies |
| Module Strategy Module strategy | Graph, ExchangeOnlineManagement, PnP, M365DSC Graph, ExchangeOnlineManagement, PnP, M365DSC | Versionen pinnen und regelmäßig aktualisieren Pin versions and update them regularly |
| Observability Observability | Runbook Logs, App Insights, Alerts Runbook logs, App Insights, alerts | Jede Automatisierung braucht Metriken und Alarmierung Every automation needs metrics and alerting |
param()
Connect-MgGraph -Identity
Get-MgGroup -Top 10 | Select-Object DisplayName,Id
# Azure Function timer trigger pseudo-code
param($Timer)
Connect-MgGraph -Identity
Invoke-MgGraphRequest -Method GET -Uri 'https://graph.microsoft.com/v1.0/auditLogs/signIns?$top=5'
CLI for Microsoft 365 und Toolvergleich CLI for Microsoft 365 and tool comparison
CLI for Microsoft 365 ist ein starkes Ergänzungswerkzeug für Skripte, Shell-basierte Pipelines und schnelle Tenant-Checks. Zusammen mit DSC, Terraform und PowerShell ergibt sich eine flexible Automatisierungslandschaft, die bewusst nach Stärken aufgeteilt werden sollte. CLI for Microsoft 365 is a strong complementary tool for scripts, shell-based pipelines, and quick tenant checks. Together with DSC, Terraform, and PowerShell, it forms a flexible automation landscape that should be split consciously by strengths.
| Tool Tool | Stärke Strength | Wann bevorzugen When to prefer it |
|---|---|---|
| CLI for Microsoft 365 CLI for Microsoft 365 | Schnelle Befehle für M365-Workloads Fast commands for Microsoft 365 workloads | Für Shell-Pipelines und leichte Automatisierung For shell pipelines and light automation |
| Microsoft365DSC Microsoft365DSC | Breite Export- und Drift-Fähigkeit Broad export and drift capability | Für Soll-Ist-Vergleich und Baseline-Erstellung For desired-versus-actual comparison and baseline creation |
| Terraform Terraform | Stateful, reviewbare deklarative Änderungen Stateful, reviewable declarative changes | Für Entra-Objekte und CI/CD For Entra objects and CI/CD |
| Bicep Bicep | Azure-nahe deklarative Deployments Azure-near declarative deployments | Wenn Entra mit Azure-Ressourcen gekoppelt ist When Entra is coupled with Azure resources |
| PowerShell PowerShell | Maximale Flexibilität und Lückenabdeckung Maximum flexibility and gap coverage | Für operative Sonderfälle und Hybridpfade For operational edge cases and hybrid paths |
| Feature Matrix Feature matrix | Vergleich von Coverage, State, Drift, Learning Curve Comparison of coverage, state, drift, learning curve | Im Zielbild bewusst dokumentieren Document consciously in the target model |
m365 login --authType deviceCode
m365 aad app list
m365 spo site list
m365 entra policy ca list
Drift Detection, Graph Batch, Delta und Pipelinebeispiele Drift detection, Graph batch, delta, and pipeline examples
Kontinuierliche Governance braucht Drift Detection, Change Tracking und skalierbare API-Nutzung. Graph Batch, Delta Queries und Change Notifications ergänzen CI/CD-Pipelines, damit Konfigurationsänderungen nicht nur deployt, sondern auch überwacht werden. Continuous governance needs drift detection, change tracking, and scalable API usage. Graph batch, delta queries, and change notifications complement CI/CD pipelines so configuration changes are not only deployed but also monitored.
Nutze OIDC oder Managed Identity für Authentifizierung, versioniere Sollzustand in Git, trenne Validate/Plan/Apply, dokumentiere Ausnahmen und betreibe Drift Detection als dauerhaften Prozess statt als sporadischen Audit-Event. Use OIDC or managed identity for authentication, version desired state in Git, separate validate, plan, and apply, document exceptions, and run drift detection as a continuous process rather than a sporadic audit event.
| Capability Capability | Beschreibung Description | Praxiswert Practical value |
|---|---|---|
| Drift Detection Drift detection | Vergleich von Ist gegen Soll Compare actual against desired state | Zentrale Grundlage für Governance und Audit Central foundation for governance and audit |
| Graph Batch Graph batch | Mehrere API-Aufrufe in einer HTTP-Anfrage Multiple API calls in one HTTP request | Sinnvoll für Reporting und Massenvorgänge Useful for reporting and bulk operations |
| Delta Queries Delta queries | Nur Änderungen seit letztem Lauf abrufen Fetch only changes since the last run | Ideal für Sync- oder Reconciliation-Jobs Ideal for sync or reconciliation jobs |
| Change Notifications Change notifications | Webhook-basiertes Ereignismodell Webhook-based event model | Ermöglicht reaktive Governance und Near-Real-Time-Workflows Enables reactive governance and near-real-time workflows |
| Monitoring Monitoring | Alerts, dashboards, remediation Alerts, dashboards, remediation | Drift ohne Reaktion ist nur schöne Telemetrie Drift without reaction is only pretty telemetry |
| Pipeline Example: Terraform Pipeline example: Terraform | Plan, Review, Apply, Drift Report Plan, review, apply, drift report | Standardfall für Entra-Konfigurationen als Code Standard case for Entra configuration as code |
| Pipeline Example: M365DSC Pipeline example: M365DSC | Export, Compare, Approve, Apply Export, compare, approve, apply | Stark für Brownfield und Security Baselines Strong for brownfield and security baselines |
| Pipeline Example: Graph Audit Pipeline example: Graph audit | Delta Query, Compare, Issue Create Delta query, compare, issue creation | Gut für automatisches Governance-Backlog Good for automated governance backlogs |
| Pipeline Example: CLI / PowerShell Pipeline example: CLI / PowerShell | Leichte Prüfungen oder schnelle Korrekturen Light checks or quick corrections | Nützlich als Ergänzung, nicht als alleiniges Delivery-Modell Useful as a complement, not as the only delivery model |
POST https://graph.microsoft.com/v1.0/$batch
Content-Type: application/json
{
"requests": [
{ "id": "1", "method": "GET", "url": "/groups?$top=10" },
{ "id": "2", "method": "GET", "url": "/applications?$top=10" }
]
}
GET https://graph.microsoft.com/v1.0/groups/delta
Authorization: Bearer <token>
# Example 1: Terraform pipeline
stages: [validate, plan, review, apply]
# Example 2: M365DSC drift
steps: Export -> Compare -> Publish artifact
# Example 3: Graph delta audit
steps: Query delta -> Compare baseline -> Create issue
# Example 4: PowerShell remediation
steps: Detect -> Approve -> Execute -> Verify