<# .SYNOPSIS Sichert die Compliance-Konfiguration (Purview) über Security & Compliance PowerShell, nur mit Get-Cmdlets. .DESCRIPTION Meldet sich mit der App-Registrierung und dem Zertifikat an (Connect-IPPSSession) und schreibt je Cmdlet eine JSON-Datei in den Zielordner, dazu einen Bericht (_compliance_report.json). Danach werden die eigenen Informationstypen (Publisher ungleich Microsoft) und die Audit-Konfiguration gesichert. Es werden keine Einstellungen geändert. Umgebungsvariablen: M365_CLIENT_ID, M365_TENANT_NAME (z. B. contoso.onmicrosoft.com), M365_CERT_PATH (Zertifikat, PEM) und M365_CERT_KEY_PATH (privater Schlüssel, PEM). .PARAMETER OutDir Zielordner, normalerweise /compliance. .EXAMPLE ./compliance.ps1 -OutDir ./backup/contoso/20261116-0557/compliance #> param([Parameter(Mandatory)][string]$OutDir) foreach ($name in 'M365_CLIENT_ID', 'M365_TENANT_NAME', 'M365_CERT_PATH', 'M365_CERT_KEY_PATH') { if (-not (Get-Item "env:$name" -ErrorAction SilentlyContinue)) { throw "environment variable $name is not set" } } New-Item -ItemType Directory -Force -Path $OutDir | Out-Null Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force 2>&1 | Out-Null $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromPemFile($env:M365_CERT_PATH, $env:M365_CERT_KEY_PATH) Connect-IPPSSession -AppId $env:M365_CLIENT_ID -Certificate $cert -Organization $env:M365_TENANT_NAME -ShowBanner:$false $report = @{} $cmdlets = 'Get-RetentionCompliancePolicy', 'Get-RetentionComplianceRule', 'Get-DlpCompliancePolicy', 'Get-DlpComplianceRule', 'Get-Label', 'Get-LabelPolicy', 'Get-ComplianceTag', 'Get-DlpSensitiveInformationType', 'Get-ComplianceCase', 'Get-AuditConfig', 'Get-UnifiedAuditLogRetentionPolicy', 'Get-ProtectionAlert', 'Get-InformationBarrierPolicy', 'Get-SupervisoryReviewPolicyV2', 'Get-SupervisoryReviewRule', 'Get-RoleGroup', 'Get-ComplianceSecurityFilter', 'Get-DlpKeywordDictionary', 'Get-AutoSensitivityLabelPolicy', 'Get-AutoSensitivityLabelRule', 'Get-ComplianceRetentionEventType', 'Get-OrganizationSegment', 'Get-PolicyConfig', 'Get-ComplianceSearch', 'Get-ManagementRoleAssignment', 'Get-AdminAuditLogConfig', 'Get-DlpSensitiveInformationTypeRulePackage', 'Get-FilePlanPropertyAuthority', 'Get-FilePlanPropertyCitation', 'Get-FilePlanPropertyDepartment', 'Get-FilePlanPropertyReferenceId', 'Get-FilePlanPropertyCategory', 'Get-FilePlanPropertySubCategory', 'Get-ComplianceRetentionEvent', 'Get-RecordReviewNotificationTemplateConfig', 'Get-IRMConfiguration' foreach ($c in ($cmdlets | Select-Object -Unique)) { try { $p = @{ ErrorAction = 'Stop' } if ($c -eq 'Get-Label') { $p.IncludeDetailedLabelActions = $true } $r = @(& $c @p) $r | ConvertTo-Json -Depth 8 -WarningAction SilentlyContinue | Set-Content "$OutDir/$($c.Substring(4)).json" $report[$c] = @{ count = $r.Count } "OK $c $($r.Count)" } catch { $m = $_.Exception.Message if ($m.Length -gt 300) { $m = $m.Substring(0, 300) } $report[$c] = @{ error = $m } "ERROR $c $m" } } $report | ConvertTo-Json -Depth 4 | Set-Content "$OutDir/_compliance_report.json" # Zweiter Teil: eigene Informationstypen und Audit-Konfiguration $all = @(Get-DlpSensitiveInformationType) "all: $($all.Count)" $custom = @($all | Where-Object { $_.Publisher -ne 'Microsoft Corporation' }) "custom: $($custom.Count)" $custom | Select-Object Name, Id, Publisher, Type, Description, RulePackId, Locale, RecommendedConfidence | ConvertTo-Json -Depth 4 | Set-Content "$OutDir/DlpSensitiveInformationType_custom.json" $all | Select-Object Name, Id, Publisher, Type | ConvertTo-Json | Set-Content "$OutDir/DlpSensitiveInformationType_names.json" foreach ($c in 'Get-AuditConfigurationPolicy', 'Get-AuditConfig') { try { $r = @(& $c -ErrorAction Stop) "OK $c $($r.Count)" $r | ConvertTo-Json -Depth 5 | Set-Content "$OutDir/$($c.Substring(4)).json" } catch { "ERROR $c " + $_.Exception.Message.Substring(0, [Math]::Min(200, $_.Exception.Message.Length)) } }