# Script Library Script Library

Organisierte Sammlung kopierfertiger PowerShell-Skripte für Benutzer, Gruppen, Sicherheit, Exchange Online, SharePoint, Teams, Reporting und Automatisierung.Organized collection of copy-ready PowerShell scripts for users, groups, security, Exchange Online, SharePoint, Teams, reporting, and automation.

User Management Scripts User Management Scripts

Zur Kategorie springen.Jump to category.

Group Management Scripts Group Management Scripts

Zur Kategorie springen.Jump to category.

Security & Compliance Scripts Security & Compliance Scripts

Zur Kategorie springen.Jump to category.

Exchange Online Scripts Exchange Online Scripts

Zur Kategorie springen.Jump to category.

SharePoint & OneDrive Scripts SharePoint & OneDrive Scripts

Zur Kategorie springen.Jump to category.

Teams Scripts Teams Scripts

Zur Kategorie springen.Jump to category.

Reporting Scripts Reporting Scripts

Zur Kategorie springen.Jump to category.

Automation & Scheduled Tasks Automation & Scheduled Tasks

Zur Kategorie springen.Jump to category.

## User Management Scripts User Management Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Export All Users Export All Users

Exportiert alle Benutzer mit Kernattributen und Kontostatus.Exports all users with core attributes and account status.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- CSV-Export CSV export

PowerShell PowerShell

    param([string]$OutputPath = ".\all-users.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Property DisplayName,UserPrincipalName,AccountEnabled,UserType
        $items | Select-Object DisplayName,UserPrincipalName,AccountEnabled,UserType | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit DisplayName, UPN, Benutzerstatus und UserType.CSV with display name, UPN, account status, and user type.

### Create Users from CSV Create Users from CSV

Erstellt neue Cloud-Benutzer aus einer CSV-Datei.Creates new cloud users from a CSV file.

Requirements Requirements

- CSV mit DisplayName,UserPrincipalName,MailNickname,Password CSV with DisplayName,UserPrincipalName,MailNickname,Password
- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.ReadWrite.All Scopes: User.ReadWrite.All

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$InputCsv,
        [string]$OutputPath = ".\created-users.csv"
    )

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.ReadWrite.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($row in (Import-Csv $InputCsv -ErrorAction Stop)) {
            $user = New-MgUser -AccountEnabled `
                               -DisplayName $row.DisplayName `
                               -MailNickname $row.MailNickname `
                               -UserPrincipalName $row.UserPrincipalName `
                               -PasswordProfile @{ ForceChangePasswordNextSignIn = $true; Password = $row.Password }
            [pscustomobject]@{ DisplayName = $user.DisplayName; UserPrincipalName = $user.UserPrincipalName; Result = "Created" }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit neu erstellten Benutzerkonten und Ergebnisstatus.CSV with created user accounts and result status.

### Disable Dormant Users Disable Dormant Users

Deaktiviert Benutzer, die länger als 120 Tage inaktiv waren.Disables users that have been inactive for more than 120 days.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.ReadWrite.All, AuditLog.Read.All Scopes: User.ReadWrite.All, AuditLog.Read.All
- Review vor Einsatz in Produktion Review before production use

PowerShell PowerShell

    param(
        [int]$InactiveDays = 120,
        [switch]$WhatIfOnly,
        [string]$OutputPath = ".\dormant-users-review.csv"
    )

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.ReadWrite.All","AuditLog.Read.All" -NoWelcome -ErrorAction Stop

        $cutoff = (Get-Date).AddDays(-$InactiveDays)
        $users = Get-MgUser -All -Property DisplayName,UserPrincipalName,AccountEnabled,SignInActivity
        $report = foreach ($user in $users | Where-Object { $_.AccountEnabled -and $_.SignInActivity.LastSuccessfulSignInDateTime -and ([datetime]$_.SignInActivity.LastSuccessfulSignInDateTime) -lt $cutoff }) {
            if (-not $WhatIfOnly) { Update-MgUser -UserId $user.UserPrincipalName -AccountEnabled:$false }
            [pscustomobject]@{ UserPrincipalName = $user.UserPrincipalName; LastSuccessfulSignIn = $user.SignInActivity.LastSuccessfulSignInDateTime; Action = $(if ($WhatIfOnly) { "Review" } else { "Disabled" }) }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit allen deaktivierten oder markierten Benutzerkonten.CSV with all disabled or flagged user accounts.

### Export Guest Users Export Guest Users

Listet alle Gastbenutzer inklusive Einladungsstatus.Lists all guest users including invitation state.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- Guest Reporting Guest reporting

PowerShell PowerShell

    param([string]$OutputPath = ".\guest-users.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Filter "userType eq 'Guest'" -Property DisplayName,UserPrincipalName,ExternalUserState,CreatedDateTime
        $items | Select-Object DisplayName,UserPrincipalName,ExternalUserState,CreatedDateTime | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Gast-UPNs, ExternalUserState und Erstellungsdatum.CSV with guest UPNs, external user state, and creation time.

### Bulk Update Department Bulk Update Department

Aktualisiert Department-Attribute für mehrere Benutzer per CSV.Updates department attributes for multiple users via CSV.

Requirements Requirements

- CSV mit UserPrincipalName,Department CSV with UserPrincipalName,Department
- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.ReadWrite.All Scopes: User.ReadWrite.All

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$InputCsv,
        [string]$OutputPath = ".\department-update-results.csv"
    )

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.ReadWrite.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($row in (Import-Csv $InputCsv -ErrorAction Stop)) {
            Update-MgUser -UserId $row.UserPrincipalName -Department $row.Department -ErrorAction Stop
            [pscustomobject]@{ UserPrincipalName = $row.UserPrincipalName; Department = $row.Department; Result = "Updated" }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit aktualisierten Departments und Bearbeitungsstatus.CSV with updated departments and processing status.

### Users Without Manager Users Without Manager

Findet Benutzer ohne zugewiesenen Manager.Finds users without an assigned manager.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- Graph Directory Data Graph directory data

PowerShell PowerShell

    param([string]$OutputPath = ".\users-without-manager.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($user in (Get-MgUser -All -Property DisplayName,UserPrincipalName)) {
            $manager = Get-MgUserManager -UserId $user.Id -ErrorAction SilentlyContinue
            if (-not $manager) { [pscustomobject]@{ DisplayName = $user.DisplayName; UserPrincipalName = $user.UserPrincipalName } }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Benutzern ohne Manager-Beziehung.CSV with users that have no manager relationship.

### Licensed User Inventory Licensed User Inventory

Zeigt alle Benutzer mit mindestens einer Lizenz.Shows all users with at least one license assigned.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- Lizenzübersicht License overview

PowerShell PowerShell

    param([string]$OutputPath = ".\licensed-users.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Property DisplayName,UserPrincipalName,AssignedLicenses,UserType
        $items | Where-Object { $_.AssignedLicenses.Count -gt 0 } | Select-Object DisplayName,UserPrincipalName,@{Name='LicenseCount';Expression={$_.AssignedLicenses.Count}},UserType | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit UPN, Lizenzanzahl und Benutzertyp.CSV with UPN, license count, and user type.

### Password Change Review Password Change Review

Exportiert Benutzer mit veraltetem Kennwortwechselstempel.Exports users with an outdated password-change timestamp.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- Nur für Cloud-Attribute nutzbar Useful only for cloud attributes

PowerShell PowerShell

    param([string]$OutputPath = ".\password-change-review.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Property DisplayName,UserPrincipalName,LastPasswordChangeDateTime
        $items | Select-Object DisplayName,UserPrincipalName,LastPasswordChangeDateTime | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit LastPasswordChangeDateTime und Review-Hinweis.CSV with last password change time and a review hint.

### Disabled Users Review Disabled Users Review

Exportiert alle deaktivierten Konten zur periodischen Bereinigung.Exports all disabled accounts for periodic cleanup.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- Cleanup Review Cleanup review

PowerShell PowerShell

    param([string]$OutputPath = ".\disabled-users.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Property DisplayName,UserPrincipalName,AccountEnabled,UserType
        $items | Where-Object { -not $_.AccountEnabled } | Select-Object DisplayName,UserPrincipalName,UserType | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit deaktivierten Konten und Benutzerstatus.CSV with disabled accounts and user state.

### Authentication Methods Inventory Authentication Methods Inventory

Listet registrierte MFA-Methoden pro Benutzer.Lists registered MFA methods per user.

Requirements Requirements

- Microsoft.Graph.Reports Microsoft.Graph.Reports
- Scopes: Reports.Read.All Scopes: Reports.Read.All
- Authentication method reports Authentication method reports

PowerShell PowerShell

    param([string]$OutputPath = ".\authentication-methods.csv")

    try {
        Import-Module Microsoft.Graph.Reports -ErrorAction Stop
        Connect-MgGraph -Scopes "Reports.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgReportAuthenticationMethodUserRegistrationDetail -All
        $items | Select-Object UserPrincipalName,UserDisplayName,@{Name='Methods';Expression={($_.MethodsRegistered -join '; ')}},DefaultMfaMethod | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit registrierten Methoden und Default-MFA-Status.CSV with registered methods and default MFA state.

## Group Management Scripts Group Management Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Group Inventory Group Inventory

Exportiert Sicherheits-, Mail- und Microsoft-365-Gruppen.Exports security, mail, and Microsoft 365 groups.

Requirements Requirements

- Microsoft.Graph.Groups Microsoft.Graph.Groups
- Scopes: Group.Read.All Scopes: Group.Read.All
- Gruppeninventur Group inventory

PowerShell PowerShell

    param([string]$OutputPath = ".\group-inventory.csv")

    try {
        Import-Module Microsoft.Graph.Groups -ErrorAction Stop
        Connect-MgGraph -Scopes "Group.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgGroup -All -Property DisplayName,MailEnabled,SecurityEnabled,GroupTypes
        $items | Select-Object DisplayName,MailEnabled,SecurityEnabled,@{Name='GroupTypes';Expression={($_.GroupTypes -join ';')}} | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Gruppentyp, MailEnabled und SecurityEnabled.CSV with group type, mail enabled, and security enabled.

### Group Members Export Group Members Export

Exportiert Mitglieder einer angegebenen Gruppe.Exports members of a specified group.

Requirements Requirements

- Microsoft.Graph.Groups Microsoft.Graph.Groups
- Scopes: Group.Read.All Scopes: Group.Read.All
- GroupId erforderlich GroupId required

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$GroupId,
        [string]$OutputPath = ".\group-members.csv"
    )

    try {
        Import-Module Microsoft.Graph.Groups -ErrorAction Stop
        Connect-MgGraph -Scopes "Group.Read.All" -NoWelcome -ErrorAction Stop

        Get-MgGroupMember -GroupId $GroupId -All |
            Select-Object Id,AdditionalProperties |
            Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Gruppenmitgliedern und Objekt-IDs.CSV with group members and object IDs.

### Bulk Add Group Members Bulk Add Group Members

Fügt per CSV mehrere Mitglieder zu einer Gruppe hinzu.Adds multiple members to a group via CSV.

Requirements Requirements

- CSV mit DirectoryObjectId CSV with DirectoryObjectId
- Microsoft.Graph.Groups Microsoft.Graph.Groups
- Scopes: GroupMember.ReadWrite.All Scopes: GroupMember.ReadWrite.All

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$GroupId,
        [Parameter(Mandatory)]
        [string]$InputCsv,
        [string]$OutputPath = ".\group-member-add-results.csv"
    )

    try {
        Import-Module Microsoft.Graph.Groups -ErrorAction Stop
        Connect-MgGraph -Scopes "GroupMember.ReadWrite.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($row in (Import-Csv $InputCsv -ErrorAction Stop)) {
            New-MgGroupMemberByRef -GroupId $GroupId -BodyParameter @{ "@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/$($row.DirectoryObjectId)" }
            [pscustomobject]@{ DirectoryObjectId = $row.DirectoryObjectId; Result = "Added" }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit hinzugefügten Mitgliedern und Ergebnisstatus.CSV with added members and result status.

### Empty Groups Report Empty Groups Report

Findet Gruppen ohne Mitglieder.Finds groups without members.

Requirements Requirements

- Microsoft.Graph.Groups Microsoft.Graph.Groups
- Scopes: Group.Read.All Scopes: Group.Read.All
- Kann bei großen Tenants länger laufen Can take longer in large tenants

PowerShell PowerShell

    param([string]$OutputPath = ".\empty-groups.csv")

    try {
        Import-Module Microsoft.Graph.Groups -ErrorAction Stop
        Connect-MgGraph -Scopes "Group.Read.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($group in (Get-MgGroup -All -Property DisplayName)) {
            if ((Get-MgGroupMember -GroupId $group.Id -Top 1 -ErrorAction SilentlyContinue | Measure-Object).Count -eq 0) {
                [pscustomobject]@{ DisplayName = $group.DisplayName; GroupId = $group.Id }
            }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit leeren Gruppen zur Review oder Bereinigung.CSV with empty groups for review or cleanup.

### Dynamic Group Rules Export Dynamic Group Rules Export

Exportiert alle dynamischen Gruppen mit Membership Rules.Exports all dynamic groups with membership rules.

Requirements Requirements

- Microsoft.Graph.Groups Microsoft.Graph.Groups
- Scopes: Group.Read.All Scopes: Group.Read.All
- Dynamische Gruppen Dynamic groups

PowerShell PowerShell

    param([string]$OutputPath = ".\dynamic-group-rules.csv")

    try {
        Import-Module Microsoft.Graph.Groups -ErrorAction Stop
        Connect-MgGraph -Scopes "Group.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgGroup -All -Property DisplayName,GroupTypes,MembershipRule,MembershipRuleProcessingState
        $items | Where-Object { $_.MembershipRule } | Select-Object DisplayName,MembershipRule,MembershipRuleProcessingState | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Gruppenname, Regel und Verarbeitungsstatus.CSV with group name, rule, and processing state.

## Security & Compliance Scripts Security & Compliance Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Conditional Access Inventory Conditional Access Inventory

Exportiert alle Conditional-Access-Richtlinien und ihren Status.Exports all Conditional Access policies and their state.

Requirements Requirements

- Microsoft.Graph.Identity.SignIns Microsoft.Graph.Identity.SignIns
- Scopes: Policy.Read.All Scopes: Policy.Read.All
- CA Governance CA governance

PowerShell PowerShell

    param([string]$OutputPath = ".\conditional-access-inventory.csv")

    try {
        Import-Module Microsoft.Graph.Identity.SignIns -ErrorAction Stop
        Connect-MgGraph -Scopes "Policy.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgIdentityConditionalAccessPolicy -All
        $items | Select-Object DisplayName,State,CreatedDateTime,ModifiedDateTime | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Richtlinienname, State und Zeitstempeln.CSV with policy name, state, and timestamps.

### MFA Coverage Snapshot MFA Coverage Snapshot

Snapshot der MFA-Registrierung mit Methoden und Standardfaktor.Snapshot of MFA registration including methods and default factor.

Requirements Requirements

- Microsoft.Graph.Reports Microsoft.Graph.Reports
- Scopes: Reports.Read.All Scopes: Reports.Read.All
- Authentication method reports Authentication method reports

PowerShell PowerShell

    param([string]$OutputPath = ".\mfa-coverage-snapshot.csv")

    try {
        Import-Module Microsoft.Graph.Reports -ErrorAction Stop
        Connect-MgGraph -Scopes "Reports.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgReportAuthenticationMethodUserRegistrationDetail -All
        $items | Select-Object UserPrincipalName,IsMfaRegistered,DefaultMfaMethod | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit MFA-Registrierungsstatus je Benutzer.CSV with MFA registration state per user.

### Privileged Roles Export Privileged Roles Export

Exportiert aktive Rollenzuweisungen aus Entra ID.Exports active role assignments from Entra ID.

Requirements Requirements

- Microsoft.Graph.Identity.Governance Microsoft.Graph.Identity.Governance
- Scopes: RoleManagement.Read.All Scopes: RoleManagement.Read.All
- PIM/Role review PIM/role review

PowerShell PowerShell

    param([string]$OutputPath = ".\privileged-roles.csv")

    try {
        Import-Module Microsoft.Graph.Identity.Governance -ErrorAction Stop
        Connect-MgGraph -Scopes "RoleManagement.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgRoleManagementDirectoryRoleAssignmentSchedule -All
        $items | Select-Object PrincipalId,RoleDefinitionId,StartDateTime,EndDateTime | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit PrincipalId und RoleDefinitionId.CSV with principal and role definition IDs.

### App Secret Expiry App Secret Expiry

Kurzer App-Secret-Ablaufbericht für Sicherheitsreviews.Short app secret expiry report for security reviews.

Requirements Requirements

- Microsoft.Graph.Applications Microsoft.Graph.Applications
- Scopes: Application.Read.All Scopes: Application.Read.All
- Credential hygiene Credential hygiene

PowerShell PowerShell

    param([string]$OutputPath = ".\app-secret-expiry-short.csv")

    try {
        Import-Module Microsoft.Graph.Applications -ErrorAction Stop
        Connect-MgGraph -Scopes "Application.Read.All" -NoWelcome -ErrorAction Stop

        $report = foreach ($app in (Get-MgApplication -All -Property DisplayName,AppId,PasswordCredentials)) {
            foreach ($secret in $app.PasswordCredentials) {
                [pscustomobject]@{ DisplayName = $app.DisplayName; AppId = $app.AppId; SecretName = $secret.DisplayName; EndDateTime = $secret.EndDateTime }
            }
        }

        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit AppId, SecretName und EndDateTime.CSV with app ID, secret name, and end date.

### Risky Users Export Risky Users Export

Exportiert Risky Users aus Identity Protection.Exports risky users from Identity Protection.

Requirements Requirements

- Microsoft.Graph.Identity.SignIns Microsoft.Graph.Identity.SignIns
- Scopes: IdentityRiskyUser.Read.All Scopes: IdentityRiskyUser.Read.All
- Entra ID P2 Entra ID P2

PowerShell PowerShell

    param([string]$OutputPath = ".\risky-users.csv")

    try {
        Import-Module Microsoft.Graph.Identity.SignIns -ErrorAction Stop
        Connect-MgGraph -Scopes "IdentityRiskyUser.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgRiskyUser -All
        $items | Select-Object Id,RiskLevel,RiskState,UserDisplayName | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Risk Level und Benutzer-ID.CSV with risk level and user ID.

### Audit Log Sign-Ins Export Audit Log Sign-Ins Export

Exportiert aktuelle Sign-In-Ereignisse aus dem Audit Log.Exports recent sign-in events from the audit log.

Requirements Requirements

- Microsoft.Graph.Identity.SignIns Microsoft.Graph.Identity.SignIns
- Scopes: AuditLog.Read.All Scopes: AuditLog.Read.All
- Audit data Audit data

PowerShell PowerShell

    param([string]$OutputPath = ".\signins-audit.csv")

    try {
        Import-Module Microsoft.Graph.Identity.SignIns -ErrorAction Stop
        Connect-MgGraph -Scopes "AuditLog.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgAuditLogSignIn -Top 500
        $items | Select-Object UserPrincipalName,AppDisplayName,CreatedDateTime,IpAddress | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit App, Benutzer, Status und IP-Adresse.CSV with app, user, status, and IP address.

### Secure Score Snapshot Secure Score Snapshot

Erzeugt einen schnellen Snapshot der Microsoft Secure Scores.Creates a quick snapshot of Microsoft secure scores.

Requirements Requirements

- Microsoft.Graph.Security Microsoft.Graph.Security
- Scopes: SecurityEvents.Read.All Scopes: SecurityEvents.Read.All
- Security dashboard input Security dashboard input

PowerShell PowerShell

    param([string]$OutputPath = ".\secure-score.csv")

    try {
        Import-Module Microsoft.Graph.Security -ErrorAction Stop
        Connect-MgGraph -Scopes "SecurityEvents.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgSecuritySecureScore -All
        $items | Select-Object CurrentScore,MaxScore,CreatedDateTime,AzureTenantId | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Secure Score, Maximum und Datum.CSV with secure score, maximum, and date.

### Sensitivity Labels Export Sensitivity Labels Export

Exportiert verfügbare Sensitivity Labels aus Compliance-Workflows.Exports available sensitivity labels from compliance workflows.

Requirements Requirements

- ExchangeOnlineManagement / Purview Rechte ExchangeOnlineManagement / Purview permissions
- Label Governance Label governance
- Compliance access Compliance access

PowerShell PowerShell

    param([string]$OutputPath = ".\sensitivity-labels.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-Label
        $items | Select-Object Name,DisplayName,Priority,ImmutableId | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Labelnamen und Priorität.CSV with label names and priority.

### Retention Policies Export Retention Policies Export

Exportiert Aufbewahrungsrichtlinien aus Purview/Compliance.Exports retention policies from Purview/compliance.

Requirements Requirements

- ExchangeOnlineManagement / Purview Rechte ExchangeOnlineManagement / Purview permissions
- Retention Governance Retention governance
- Compliance access Compliance access

PowerShell PowerShell

    param([string]$OutputPath = ".\retention-policies.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-RetentionCompliancePolicy
        $items | Select-Object Name,Mode,ExchangeLocation,SharePointLocation,OneDriveLocation | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Policy-Name, Mode und Workload-Details.CSV with policy name, mode, and workload details.

### External Sharing Events External Sharing Events

Sammelt externe Sharing-Ereignisse aus dem Unified Audit Log.Collects external sharing events from the unified audit log.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Audit Logging aktiviert Audit logging enabled
- Unified Audit Search Unified audit search

PowerShell PowerShell

    param([string]$OutputPath = ".\external-sharing-events.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        Search-UnifiedAuditLog -StartDate (Get-Date).AddDays(-30) -EndDate (Get-Date) -Operations SharingSet,AnonymousLinkCreated -ResultSize 5000 |
            Select-Object CreationDate,Operations,UserIds,AuditData |
            Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Sharing-Operationen aus SharePoint/OneDrive.CSV with sharing operations from SharePoint/OneDrive.

## Exchange Online Scripts Exchange Online Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Mailbox Inventory Mailbox Inventory

Exportiert alle Benutzerpostfächer.Exports all user mailboxes.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- Mailbox overview Mailbox overview

PowerShell PowerShell

    param([string]$OutputPath = ".\mailbox-inventory.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-EXOMailbox -ResultSize Unlimited
        $items | Select-Object DisplayName,UserPrincipalName,PrimarySmtpAddress,RecipientTypeDetails | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit SMTP-Adresse und Typ.CSV with SMTP address and type.

### Mailbox Permissions Export Mailbox Permissions Export

Exportiert Mailboxberechtigungen für ein Zielpostfach.Exports mailbox permissions for a target mailbox.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Mailbox Identity Mailbox identity
- Permission review Permission review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$Identity,
        [string]$OutputPath = ".\mailbox-permissions.csv"
    )

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
        Get-MailboxPermission -Identity $Identity | Select-Object User,AccessRights,IsInherited | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }
    finally { Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue }

Expected output:Expected output: CSV mit Usern und AccessRights.CSV with users and access rights.

### Mail Forwarding Report Mail Forwarding Report

Zeigt konfigurierte Mailweiterleitungen.Shows configured mail forwarding.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- Forwarding review Forwarding review

PowerShell PowerShell

    param([string]$OutputPath = ".\mail-forwarding-report.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-Mailbox -ResultSize Unlimited
        $items | Where-Object { $_.ForwardingAddress -or $_.ForwardingSmtpAddress } | Select-Object DisplayName,PrimarySmtpAddress,ForwardingAddress,ForwardingSmtpAddress,DeliverToMailboxAndForward | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit ForwardingAddress und DeliverToMailboxAndForward.CSV with forwarding address and deliver-to-mailbox-and-forward.

### Transport Rules Export Transport Rules Export

Exportiert alle Mailflow-Regeln.Exports all mail flow rules.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- Transport review Transport review

PowerShell PowerShell

    param([string]$OutputPath = ".\transport-rules.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-TransportRule
        $items | Select-Object Name,Mode,Priority,State | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Regelname, Mode und Priority.CSV with rule name, mode, and priority.

### Shared Mailbox Inventory Shared Mailbox Inventory

Listet alle Shared Mailboxes.Lists all shared mailboxes.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- Shared mailbox overview Shared mailbox overview

PowerShell PowerShell

    param([string]$OutputPath = ".\shared-mailboxes.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails SharedMailbox
        $items | Select-Object DisplayName,PrimarySmtpAddress,WhenCreated | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Shared Mailboxes.CSV with shared mailboxes.

### Distribution Groups Export Distribution Groups Export

Exportiert klassische Distribution Groups.Exports classic distribution groups.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- DL review DL review

PowerShell PowerShell

    param([string]$OutputPath = ".\distribution-groups.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop

        $items = Get-DistributionGroup -ResultSize Unlimited
        $items | Select-Object DisplayName,Alias,PrimarySmtpAddress,ManagedBy | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue
    }

Expected output:Expected output: CSV mit Alias und Primary SMTP.CSV with alias and primary SMTP.

### Mailbox Size Summary Mailbox Size Summary

Kurzzusammenfassung der Postfachgrößen.Quick summary of mailbox sizes.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Exchange Admin Exchange admin
- Mailbox statistics Mailbox statistics

PowerShell PowerShell

    param([string]$OutputPath = ".\mailbox-size-summary.csv")

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
        $report = foreach ($mb in (Get-EXOMailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox)) {
            $stats = Get-EXOMailboxStatistics -Identity $mb.UserPrincipalName
            [pscustomobject]@{ UserPrincipalName = $mb.UserPrincipalName; TotalItemSize = $stats.TotalItemSize; ItemCount = $stats.ItemCount }
        }
        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }
    finally { Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue }

Expected output:Expected output: CSV mit Größe und ItemCount je Mailbox.CSV with size and item count per mailbox.

### Inbox Rules Export Inbox Rules Export

Exportiert Posteingangsregeln für ein Benutzerpostfach.Exports inbox rules for a user mailbox.

Requirements Requirements

- ExchangeOnlineManagement ExchangeOnlineManagement
- Mailbox Identity Mailbox identity
- Rule review Rule review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$Mailbox,
        [string]$OutputPath = ".\inbox-rules.csv"
    )

    try {
        Import-Module ExchangeOnlineManagement -ErrorAction Stop
        Connect-ExchangeOnline -ShowBanner:$false -ErrorAction Stop
        Get-InboxRule -Mailbox $Mailbox | Select-Object Name,Enabled,ForwardTo,RedirectTo,DeleteMessage | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }
    finally { Disconnect-ExchangeOnline -Confirm:$false -ErrorAction SilentlyContinue }

Expected output:Expected output: CSV mit RuleName, Enabled und Forwarding-Aktionen.CSV with rule name, enabled state, and forwarding actions.

## SharePoint & OneDrive Scripts SharePoint & OneDrive Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### SharePoint Sites Inventory SharePoint Sites Inventory

Inventur aller SharePoint-Sites.Inventory of all SharePoint sites.

Requirements Requirements

- Microsoft.Online.SharePoint.PowerShell Microsoft.Online.SharePoint.PowerShell
- Admin URL Admin URL
- SharePoint Admin SharePoint admin

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$AdminUrl,
        [string]$OutputPath = ".\sharepoint-sites.csv"
    )

    try {
        Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
        Connect-SPOService -Url $AdminUrl -ErrorAction Stop

        $items = Get-SPOSite -Limit All
        $items | Select-Object Url,Title,Template,Owner | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }

Expected output:Expected output: CSV mit URL, Titel und Template.CSV with URL, title, and template.

### Site Storage Export Site Storage Export

Exportiert Speicherverbrauch pro Site.Exports storage consumption per site.

Requirements Requirements

- Microsoft.Online.SharePoint.PowerShell Microsoft.Online.SharePoint.PowerShell
- Admin URL Admin URL
- Storage review Storage review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$AdminUrl,
        [string]$OutputPath = ".\sharepoint-storage.csv"
    )

    try {
        Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
        Connect-SPOService -Url $AdminUrl -ErrorAction Stop

        $items = Get-SPOSite -Limit All -Detailed
        $items | Select-Object Url,Title,StorageUsageCurrent,StorageQuota | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }

Expected output:Expected output: CSV mit StorageUsageCurrent und StorageQuota.CSV with storage usage and quota.

### OneDrive Sites Export OneDrive Sites Export

Listet OneDrive-Personal-Sites.Lists OneDrive personal sites.

Requirements Requirements

- Microsoft.Online.SharePoint.PowerShell Microsoft.Online.SharePoint.PowerShell
- Admin URL Admin URL
- OneDrive review OneDrive review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$AdminUrl,
        [string]$OutputPath = ".\onedrive-sites.csv"
    )

    try {
        Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
        Connect-SPOService -Url $AdminUrl -ErrorAction Stop

        $items = Get-SPOSite -IncludePersonalSite $true -Limit All
        $items | Where-Object { $_.Url -like '*-my.sharepoint.com/personal/*' } | Select-Object Url,Owner,StorageUsageCurrent | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }

Expected output:Expected output: CSV mit Owner und URL der Personal Sites.CSV with owner and URL of personal sites.

### External Users Export External Users Export

Exportiert externe SharePoint-Benutzer.Exports external SharePoint users.

Requirements Requirements

- Microsoft.Online.SharePoint.PowerShell Microsoft.Online.SharePoint.PowerShell
- Admin URL Admin URL
- External sharing review External sharing review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$AdminUrl,
        [string]$OutputPath = ".\sharepoint-external-users.csv"
    )

    try {
        Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
        Connect-SPOService -Url $AdminUrl -ErrorAction Stop
        Get-SPOExternalUser -Position 0 -PageSize 500 |
            Select-Object DisplayName,Email,AcceptedAs,InvitedBy |
            Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit AcceptedAs und InvitedBy.CSV with accepted-as and invited-by data.

### Site Owners Export Site Owners Export

Exportiert Site-Owner-Zuordnungen.Exports site owner assignments.

Requirements Requirements

- Microsoft.Online.SharePoint.PowerShell Microsoft.Online.SharePoint.PowerShell
- Admin URL Admin URL
- Owner review Owner review

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$AdminUrl,
        [string]$OutputPath = ".\site-owners.csv"
    )

    try {
        Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction Stop
        Connect-SPOService -Url $AdminUrl -ErrorAction Stop

        $items = Get-SPOSite -Limit All
        $items | Select-Object Url,Title,Owner | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }

Expected output:Expected output: CSV mit URL und Owner.CSV with URL and owner.

## Teams Scripts Teams Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Teams Inventory Teams Inventory

Inventur aller Teams.Inventory of all teams.

Requirements Requirements

- MicrosoftTeams MicrosoftTeams
- Teams Administrator Teams administrator
- Teams list Teams list

PowerShell PowerShell

    param([string]$OutputPath = ".\teams-inventory.csv")

    try {
        Import-Module MicrosoftTeams -ErrorAction Stop
        Connect-MicrosoftTeams -ErrorAction Stop
        Get-Team | Select-Object DisplayName,GroupId,Visibility,Archived | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit Teamname, GroupId und Visibility.CSV with team name, group ID, and visibility.

### Team Owners Export Team Owners Export

Exportiert Owner je Team.Exports owners per team.

Requirements Requirements

- MicrosoftTeams MicrosoftTeams
- Teams Administrator Teams administrator
- Owner review Owner review

PowerShell PowerShell

    param([string]$OutputPath = ".\team-owners.csv")

    try {
        Import-Module MicrosoftTeams -ErrorAction Stop
        Connect-MicrosoftTeams -ErrorAction Stop
        $report = foreach ($team in (Get-Team)) {
            Get-TeamUser -GroupId $team.GroupId | Where-Object Role -eq 'Owner' | ForEach-Object {
                [pscustomobject]@{ Team = $team.DisplayName; User = $_.User; Role = $_.Role }
            }
        }
        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit Teamname und Owner-UPNs.CSV with team name and owner UPNs.

### Team Guests Export Team Guests Export

Zeigt Gastbenutzer in Teams.Shows guest users in Teams.

Requirements Requirements

- MicrosoftTeams MicrosoftTeams
- Teams Administrator Teams administrator
- Guest review Guest review

PowerShell PowerShell

    param([string]$OutputPath = ".\team-guests.csv")

    try {
        Import-Module MicrosoftTeams -ErrorAction Stop
        Connect-MicrosoftTeams -ErrorAction Stop
        $report = foreach ($team in (Get-Team)) {
            Get-TeamUser -GroupId $team.GroupId | Where-Object User -like '*#EXT#*' | ForEach-Object {
                [pscustomobject]@{ Team = $team.DisplayName; Guest = $_.User }
            }
        }
        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit Teamname und Gastkonto.CSV with team name and guest account.

### Channels Export Channels Export

Exportiert Kanäle aller Teams.Exports channels from all teams.

Requirements Requirements

- MicrosoftTeams MicrosoftTeams
- Teams Administrator Teams administrator
- Channel review Channel review

PowerShell PowerShell

    param([string]$OutputPath = ".\team-channels.csv")

    try {
        Import-Module MicrosoftTeams -ErrorAction Stop
        Connect-MicrosoftTeams -ErrorAction Stop
        $report = foreach ($team in (Get-Team)) {
            Get-TeamChannel -GroupId $team.GroupId | ForEach-Object {
                [pscustomobject]@{ Team = $team.DisplayName; Channel = $_.DisplayName; MembershipType = $_.MembershipType }
            }
        }
        $report | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit Teamname, Kanalname und MembershipType.CSV with team name, channel name, and membership type.

### Meeting Policies Export Meeting Policies Export

Exportiert Teams Meeting Policies.Exports Teams meeting policies.

Requirements Requirements

- MicrosoftTeams MicrosoftTeams
- Teams Administrator Teams administrator
- Policy review Policy review

PowerShell PowerShell

    param([string]$OutputPath = ".\teams-meeting-policies.csv")

    try {
        Import-Module MicrosoftTeams -ErrorAction Stop
        Connect-MicrosoftTeams -ErrorAction Stop
        Get-CsTeamsMeetingPolicy | Select-Object Identity,AllowAnonymousUsersToStartMeeting,AllowCloudRecording,MediaBitRateKb | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }

Expected output:Expected output: CSV mit Policyname und wichtigen Flags.CSV with policy name and key flags.

## Reporting Scripts Reporting Scripts

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### License Summary License Summary

Zusammenfassung belegter SKUs.Summary of consumed SKUs.

Requirements Requirements

- Microsoft.Graph.Identity.DirectoryManagement Microsoft.Graph.Identity.DirectoryManagement
- Scopes: Organization.Read.All Scopes: Organization.Read.All
- SKU summary SKU summary

PowerShell PowerShell

    param([string]$OutputPath = ".\license-summary.csv")

    try {
        Import-Module Microsoft.Graph.Identity.DirectoryManagement -ErrorAction Stop
        Connect-MgGraph -Scopes "Organization.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgSubscribedSku -All
        $items | Select-Object SkuPartNumber,ConsumedUnits,PrepaidUnits | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit SKU und ConsumedUnits.CSV with SKU and consumed units.

### Sign-In Heatmap Export Sign-In Heatmap Export

Aggregiert Sign-Ins nach Stunde.Aggregates sign-ins by hour.

Requirements Requirements

- Microsoft.Graph.Identity.SignIns Microsoft.Graph.Identity.SignIns
- Scopes: AuditLog.Read.All Scopes: AuditLog.Read.All
- Heatmap source Heatmap source

PowerShell PowerShell

    param([string]$OutputPath = ".\signin-heatmap-export.csv")

    try {
        Import-Module Microsoft.Graph.Identity.SignIns -ErrorAction Stop
        Connect-MgGraph -Scopes "AuditLog.Read.All" -NoWelcome -ErrorAction Stop
        Get-MgAuditLogSignIn -Top 1000 |
            Group-Object { $_.CreatedDateTime.Hour } |
            Select-Object @{Name='Hour';Expression={[int]$_.Name}},Count |
            Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch { Write-Error "Script failed: $($_.Exception.Message)"; throw }
    finally { Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null }

Expected output:Expected output: CSV mit Stunde und Anzahl.CSV with hour and count.

### Inactive Licensed Users Inactive Licensed Users

Findet lizenzierte Benutzer ohne aktuelle Aktivität.Finds licensed users without recent activity.

Requirements Requirements

- Microsoft.Graph.Users Microsoft.Graph.Users
- Scopes: User.Read.All Scopes: User.Read.All
- License cleanup License cleanup

PowerShell PowerShell

    param([string]$OutputPath = ".\inactive-licensed-users.csv")

    try {
        Import-Module Microsoft.Graph.Users -ErrorAction Stop
        Connect-MgGraph -Scopes "User.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgUser -All -Property DisplayName,UserPrincipalName,AssignedLicenses,SignInActivity
        $items | Where-Object { $_.AssignedLicenses.Count -gt 0 } | Select-Object DisplayName,UserPrincipalName,@{Name='LicenseCount';Expression={$_.AssignedLicenses.Count}},@{Name='LastSignIn';Expression={$_.SignInActivity.LastSuccessfulSignInDateTime}} | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Lizenzanzahl und letzter Anmeldung.CSV with license count and last sign-in.

### Managed Devices Inventory Managed Devices Inventory

Inventur verwalteter Intune-Geräte.Inventory of managed Intune devices.

Requirements Requirements

- Microsoft.Graph.DeviceManagement Microsoft.Graph.DeviceManagement
- Scopes: DeviceManagementManagedDevices.Read.All Scopes: DeviceManagementManagedDevices.Read.All
- Intune access Intune access

PowerShell PowerShell

    param([string]$OutputPath = ".\managed-devices.csv")

    try {
        Import-Module Microsoft.Graph.DeviceManagement -ErrorAction Stop
        Connect-MgGraph -Scopes "DeviceManagementManagedDevices.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgDeviceManagementManagedDevice -All
        $items | Select-Object DeviceName,UserPrincipalName,OperatingSystem,ComplianceState | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Gerät, Benutzer und Compliance-Status.CSV with device, user, and compliance state.

### Applications Inventory Applications Inventory

Inventur aller App-Registrierungen.Inventory of all app registrations.

Requirements Requirements

- Microsoft.Graph.Applications Microsoft.Graph.Applications
- Scopes: Application.Read.All Scopes: Application.Read.All
- App inventory App inventory

PowerShell PowerShell

    param([string]$OutputPath = ".\applications-inventory.csv")

    try {
        Import-Module Microsoft.Graph.Applications -ErrorAction Stop
        Connect-MgGraph -Scopes "Application.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgApplication -All
        $items | Select-Object DisplayName,AppId,SignInAudience,PublisherDomain | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit DisplayName, AppId und SignInAudience.CSV with display name, app ID, and sign-in audience.

### Service Principals Inventory Service Principals Inventory

Inventur aller Service Principals.Inventory of all service principals.

Requirements Requirements

- Microsoft.Graph.Applications Microsoft.Graph.Applications
- Scopes: Application.Read.All Scopes: Application.Read.All
- Service principal review Service principal review

PowerShell PowerShell

    param([string]$OutputPath = ".\service-principals-inventory.csv")

    try {
        Import-Module Microsoft.Graph.Applications -ErrorAction Stop
        Connect-MgGraph -Scopes "Application.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgServicePrincipal -All
        $items | Select-Object DisplayName,AppId,ServicePrincipalType,AccountEnabled | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit SPN, AppId und ServicePrincipalType.CSV with SPN, app ID, and service principal type.

### Admin Role Assignments Admin Role Assignments

Exportiert Rollenzuweisungen für Adminrollen.Exports role assignments for admin roles.

Requirements Requirements

- Microsoft.Graph.Identity.Governance Microsoft.Graph.Identity.Governance
- Scopes: RoleManagement.Read.All Scopes: RoleManagement.Read.All
- Role governance Role governance

PowerShell PowerShell

    param([string]$OutputPath = ".\admin-role-assignments.csv")

    try {
        Import-Module Microsoft.Graph.Identity.Governance -ErrorAction Stop
        Connect-MgGraph -Scopes "RoleManagement.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgRoleManagementDirectoryRoleAssignmentSchedule -All
        $items | Select-Object PrincipalId,RoleDefinitionId,StartDateTime,EndDateTime | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit PrincipalId und RoleDefinitionId.CSV with principal and role definition IDs.

### Verified Domains Export Verified Domains Export

Exportiert Domänenstatus und Authentifizierungstyp.Exports domain state and authentication type.

Requirements Requirements

- Microsoft.Graph.Identity.DirectoryManagement Microsoft.Graph.Identity.DirectoryManagement
- Scopes: Directory.Read.All Scopes: Directory.Read.All
- Domain inventory Domain inventory

PowerShell PowerShell

    param([string]$OutputPath = ".\verified-domains.csv")

    try {
        Import-Module Microsoft.Graph.Identity.DirectoryManagement -ErrorAction Stop
        Connect-MgGraph -Scopes "Directory.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgDomain -All
        $items | Select-Object Id,IsVerified,AuthenticationType,IsDefault | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Id, IsVerified und AuthenticationType.CSV with ID, verified state, and authentication type.

### Mailbox Activity Report Mailbox Activity Report

Exportiert Mailbox Activity aus Microsoft 365 Reports.Exports mailbox activity from Microsoft 365 reports.

Requirements Requirements

- Microsoft.Graph.Reports Microsoft.Graph.Reports
- Scopes: Reports.Read.All Scopes: Reports.Read.All
- Usage reporting Usage reporting

PowerShell PowerShell

    param([string]$OutputPath = ".\mailbox-activity-report.csv")

    try {
        Import-Module Microsoft.Graph.Reports -ErrorAction Stop
        Connect-MgGraph -Scopes "Reports.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgReportMailboxUsageDetail -Period D30
        $items | Select-Object * | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Aktivitätswerten pro Benutzerpostfach.CSV with activity values per mailbox user.

### M365 Usage Snapshot M365 Usage Snapshot

Sammelt einen schnellen Usage-Snapshot für OneDrive und Teams.Collects a quick usage snapshot for OneDrive and Teams.

Requirements Requirements

- Microsoft.Graph.Reports Microsoft.Graph.Reports
- Scopes: Reports.Read.All Scopes: Reports.Read.All
- Usage reporting Usage reporting

PowerShell PowerShell

    param([string]$OutputPath = ".\m365-usage-snapshot.csv")

    try {
        Import-Module Microsoft.Graph.Reports -ErrorAction Stop
        Connect-MgGraph -Scopes "Reports.Read.All" -NoWelcome -ErrorAction Stop

        $items = Get-MgReportTeamUserActivityUserDetail -Period D7
        $items | Select-Object * | Export-Csv $OutputPath -NoTypeInformation -Encoding UTF8
    }
    catch {
        Write-Error "Script failed: $($_.Exception.Message)"
        throw
    }
    finally {
        Disconnect-MgGraph -ErrorAction SilentlyContinue | Out-Null
    }

Expected output:Expected output: CSV mit Kennzahlen aus Teams- und OneDrive-Reports.CSV with metrics from Teams and OneDrive reports.

## Automation & Scheduled Tasks Automation & Scheduled Tasks

Jeder Eintrag enthält eine kurze Beschreibung, Voraussetzungen, kopierbaren PowerShell-Code und die erwartete Ausgabe.Each entry contains a short description, prerequisites, copyable PowerShell code, and the expected output.

### Register Daily User Report Task Register Daily User Report Task

Registriert eine tägliche geplante Aufgabe für einen User-Report.Registers a daily scheduled task for a user report.

Requirements Requirements

- Lokaler Windows Task Scheduler Local Windows Task Scheduler
- Pfad zum Reportskript Path to the report script
- Adminrechte auf dem Host Admin rights on the host

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$ScriptPath
    )

    $action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$ScriptPath`""
    $trigger = New-ScheduledTaskTrigger -Daily -At 06:00
    $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest
    Register-ScheduledTask -TaskName "Daily-User-Inventory" -Action $action -Trigger $trigger -Principal $principal

Expected output:Expected output: Registrierte Scheduled Task mit täglichem Trigger.Registered scheduled task with a daily trigger.

### Retry Wrapper Template Retry Wrapper Template

Generischer Retry-Wrapper für instabile API-Aufrufe.Generic retry wrapper for unstable API calls.

Requirements Requirements

- Lokales PowerShell Local PowerShell
- Für API-/REST-Workflows For API/REST workflows
- Wiederverwendbare Funktion Reusable function

PowerShell PowerShell

    function Invoke-WithRetry {
        param([scriptblock]$ScriptBlock,[int]$MaxAttempts = 5)
        for ($attempt = 1; $attempt -le $MaxAttempts; $attempt++) {
            try { return & $ScriptBlock }
            catch {
                if ($attempt -eq $MaxAttempts) { throw }
                Start-Sleep -Seconds ([math]::Pow(2,$attempt))
            }
        }
    }

    Invoke-WithRetry -ScriptBlock { Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/organization" }

Expected output:Expected output: Wiederverwendbare Funktion mit Exponential Backoff.Reusable function with exponential backoff.

### Webhook Notification Sender Webhook Notification Sender

Sendet eine JSON-Nachricht an einen Webhook nach einem Lauf.Sends a JSON message to a webhook after a run.

Requirements Requirements

- Webhook URL Webhook URL
- Lokales PowerShell Local PowerShell
- JSON payload JSON payload

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$WebhookUrl,
        [string]$Message = "Report completed"
    )

    $payload = @{ text = $Message; generatedAt = (Get-Date) } | ConvertTo-Json
    Invoke-RestMethod -Method Post -Uri $WebhookUrl -Body $payload -ContentType "application/json"

Expected output:Expected output: HTTP POST an den angegebenen Webhook.HTTP POST to the specified webhook.

### Archive CSV Reports Archive CSV Reports

Verschiebt ältere CSV-Reports in ein Archivverzeichnis.Moves older CSV reports into an archive directory.

Requirements Requirements

- Lokales Dateisystem Local file system
- Report-Ordner Report folder
- Archivpfad Archive path

PowerShell PowerShell

    param(
        [string]$SourceFolder = ".",
        [string]$ArchiveFolder = ".\archive",
        [int]$OlderThanDays = 7
    )

    if (-not (Test-Path $ArchiveFolder)) { New-Item -ItemType Directory -Path $ArchiveFolder | Out-Null }
    Get-ChildItem $SourceFolder -Filter *.csv |
        Where-Object LastWriteTime -lt (Get-Date).AddDays(-$OlderThanDays) |
        Move-Item -Destination $ArchiveFolder

Expected output:Expected output: Archivierte CSV-Dateien mit Erstellungsdatum.Archived CSV files with creation date.

### Start Transcript Job Wrapper Start Transcript Job Wrapper

Startet einen Lauf mit Transcript und Fehlerprotokollierung.Starts a run with transcript and error logging.

Requirements Requirements

- Lokales PowerShell Local PowerShell
- Pfad zum Zielsript Path to the target script
- Logging-Verzeichnis Logging folder

PowerShell PowerShell

    param(
        [Parameter(Mandatory)]
        [string]$ScriptPath,
        [string]$LogFolder = ".\logs"
    )

    if (-not (Test-Path $LogFolder)) { New-Item -ItemType Directory -Path $LogFolder | Out-Null }
    $log = Join-Path $LogFolder ("run-" + (Get-Date -Format "yyyyMMdd-HHmmss") + ".log")

    Start-Transcript -Path $log
    try { & $ScriptPath }
    finally { Stop-Transcript }

Expected output:Expected output: Transcript-Datei und Fehlerlog pro Lauf.Transcript file and error log per run.