Policies: Admin-Vorlagen-Export gehärtet (resiliente Liste + sichtbare Fehler)
- Get-GraphPolicyList: $expand=assignments pro Typ absichern. groupPolicyConfigurations (Administrative Vorlagen) lehnt den Expand teils mit 400 ab -> dann scheiterte das Laden und der Export ließ die Policies still weg. Jetzt Fallback auf Laden ohne Zuweisungen, damit der Typ erscheint und exportierbar bleibt. - Export-PoliciesEndpoint: Detail-Fehler nicht mehr verschlucken, sondern pro Policy in 'errors' zurückgeben (+ Log). - Frontend: Export-Fehler werden im Toast gemeldet (kein stiller Teil-Export mehr). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+20
-5
@@ -154,8 +154,17 @@ function Get-GraphPolicyList {
|
||||
$cfg = Get-PolicyTypeConfig $Type
|
||||
if (-not $cfg) { throw "Unbekannter Policy-Typ: $Type" }
|
||||
# Zuweisungen gleich mitladen ($expand=assignments), damit die Liste je Policy
|
||||
# Anzahl + aufgeloeste Ziele zeigen kann.
|
||||
$raw = Get-GraphPaged -Uri "https://graph.microsoft.com/beta/deviceManagement/$($cfg.Collection)?`$expand=assignments"
|
||||
# Anzahl + aufgeloeste Ziele zeigen kann. Nicht jede deviceManagement-Collection
|
||||
# unterstuetzt $expand=assignments (z.B. groupPolicyConfigurations lehnt es teils
|
||||
# mit 400 ab) -> im Fehlerfall ohne Zuweisungen laden, damit der Typ ueberhaupt
|
||||
# erscheint (und exportierbar bleibt).
|
||||
$listBase = "https://graph.microsoft.com/beta/deviceManagement/$($cfg.Collection)"
|
||||
try {
|
||||
$raw = Get-GraphPaged -Uri ($listBase + '?$expand=assignments')
|
||||
} catch {
|
||||
Write-Host " [POLICIES] $($cfg.Key): `$expand=assignments nicht unterstuetzt -> lade ohne Zuweisungen ($($_.Exception.Message))" -ForegroundColor DarkYellow
|
||||
$raw = Get-GraphPaged -Uri $listBase
|
||||
}
|
||||
$items = @()
|
||||
$needGroups = @{} # eindeutige Gruppen-Ids ueber alle Policies (fuer 1 Bulk-Lookup)
|
||||
foreach ($r in $raw) {
|
||||
@@ -592,10 +601,16 @@ function Export-PoliciesEndpoint {
|
||||
|
||||
$files = @()
|
||||
$exports = @()
|
||||
$errors = @()
|
||||
foreach ($id in $ids) {
|
||||
$policy = $null
|
||||
try { $policy = Get-GraphPolicyDetail -Type $type -Id ([string]$id) } catch {}
|
||||
if (-not $policy) { continue }
|
||||
try { $policy = Get-GraphPolicyDetail -Type $type -Id ([string]$id) }
|
||||
catch {
|
||||
$errors += @{ id = [string]$id; error = $_.Exception.Message }
|
||||
Write-Host " [EXPORT] $type/$id fehlgeschlagen: $($_.Exception.Message)" -ForegroundColor DarkYellow
|
||||
continue
|
||||
}
|
||||
if (-not $policy) { $errors += @{ id = [string]$id; error = 'Leere Antwort von Graph' }; continue }
|
||||
|
||||
$displayName = Get-PolicyDisplayName $policy
|
||||
$exportData = [ordered]@{
|
||||
@@ -623,7 +638,7 @@ function Export-PoliciesEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
return @{ ok = $true; exportedCount = $exports.Count; files = @($files); exports = @($exports) }
|
||||
return @{ ok = $true; exportedCount = $exports.Count; files = @($files); exports = @($exports); errors = @($errors) }
|
||||
}
|
||||
|
||||
# Liste des Server-Archivs (fuer optionalen Server-seitigen Re-Import).
|
||||
|
||||
Reference in New Issue
Block a user