v0.1.31 — Policy-Konsolidierung, Geraete-Export nach Gruppe, Gruppen-in-Gruppen
Build & Release MSI / build-msi (push) Canceled after 0s
Build & Release MSI / build-msi (push) Canceled after 0s
- Policies zusammenfuehren (Settings Catalog -> eine neue Policy, Konfliktaufloesung) - Geraete-Tab: Gruppen-Filter (Live-Suche) + CSV-Export der angezeigten Liste - Group Management: bestehende Gruppen als Mitglied hinzufuegen (verschachtelt) - Fix: Geraete "Invalid Date" (ISO-Normalisierung) + Datums-/Spalten-Sortierung - Doku (README/CHANGELOG) + Version-Bump 0.1.31 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+119
-4
@@ -58,6 +58,7 @@ function Invoke-ApiHandler {
|
||||
"GET /api/policies/exports" { return Get-PolicyExportsEndpoint }
|
||||
"POST /api/policies/import" { return Import-PoliciesEndpoint -Body $Body }
|
||||
"POST /api/policies/assign" { return Invoke-PolicyAssignEndpoint -Body $Body }
|
||||
"POST /api/policies/consolidate" { return Invoke-PolicyConsolidateEndpoint -Body $Body }
|
||||
"POST /api/policies/git-snapshot" { return Invoke-PolicyGitSnapshotEndpoint }
|
||||
"POST /api/pickfolder" { return Invoke-FolderPickerEndpoint -Body $Body }
|
||||
|
||||
@@ -71,6 +72,9 @@ function Invoke-ApiHandler {
|
||||
if ($Method -eq "GET" -and $Path -match "^/api/groups/([^/]+)/members/export$") {
|
||||
return Get-GroupMembersExportEndpoint -GroupId $matches[1]
|
||||
}
|
||||
if ($Method -eq "GET" -and $Path -match "^/api/groups/([^/]+)/devices/export$") {
|
||||
return Get-GroupDevicesExportEndpoint -GroupId $matches[1]
|
||||
}
|
||||
|
||||
if ($Method -eq "GET" -and $Path -match "^/api/groups/([^/]+)/members$") {
|
||||
return Get-GroupMembersEndpoint -GroupId $matches[1]
|
||||
@@ -1608,6 +1612,117 @@ function Get-GroupMembersExportEndpoint {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-GroupDevicesExportEndpoint {
|
||||
# Loest die User einer Gruppe (inkl. verschachtelter Untergruppen) auf und liefert
|
||||
# deren Intune-Geraete (Geraete, deren PRIMAERER Benutzer in der Gruppe ist) fuer
|
||||
# einen CSV-Export. Geraete werden per $batch ueber userId eq '<id>' geholt.
|
||||
param([string]$GroupId)
|
||||
$err = Test-Connected
|
||||
if ($err) { return $err }
|
||||
if ([string]::IsNullOrWhiteSpace($GroupId)) { return @{ __status = 400; error = "GroupId fehlt" } }
|
||||
|
||||
$groupName = $GroupId
|
||||
try {
|
||||
$g = Get-GraphGroupById -Id $GroupId -Property @("id","displayName")
|
||||
if ($g.displayName) { $groupName = [string]$g.displayName }
|
||||
} catch {
|
||||
return @{ __status = 404; error = "Gruppe nicht gefunden: $($_.Exception.Message)" }
|
||||
}
|
||||
|
||||
Write-Host "[GRP-DEV-EXPORT] Geraete-Export fuer Gruppe '$groupName' ($GroupId)" -ForegroundColor Cyan
|
||||
$sw = [System.Diagnostics.Stopwatch]::StartNew()
|
||||
|
||||
# User aufloesen + deduplizieren (nur eindeutige Entra-User-Ids)
|
||||
$allUsers = @(Resolve-GroupMembersWithNesting -GroupId $GroupId -GroupName $groupName)
|
||||
$seen = @{}
|
||||
$userIds = [System.Collections.Generic.List[string]]::new()
|
||||
$userMap = @{} # userId -> @{ Upn; DisplayName } (aus den Gruppen-Mitgliedern)
|
||||
foreach ($u in $allUsers) {
|
||||
$uid = [string]$u.Id
|
||||
if ($uid -and -not $seen.ContainsKey($uid)) {
|
||||
$seen[$uid] = $true
|
||||
$userIds.Add($uid)
|
||||
$userMap[$uid] = @{ Upn = [string]$u.UserPrincipalName; DisplayName = [string]$u.DisplayName }
|
||||
}
|
||||
}
|
||||
if ($userIds.Count -eq 0) {
|
||||
return @{ ok = $true; groupId = $GroupId; groupName = $groupName; userCount = 0; items = @(); count = 0; resolvedMs = [int]$sw.ElapsedMilliseconds }
|
||||
}
|
||||
|
||||
$select = 'id,deviceName,userDisplayName,userPrincipalName,operatingSystem,osVersion,complianceState,serialNumber,model,manufacturer,lastSyncDateTime,enrolledDateTime'
|
||||
$batchSize = 20
|
||||
$devSeen = @{}
|
||||
$items = [System.Collections.Generic.List[object]]::new()
|
||||
$ids = $userIds.ToArray()
|
||||
$script:GrpDevErrors = @()
|
||||
|
||||
for ($i = 0; $i -lt $ids.Count; $i += $batchSize) {
|
||||
$chunk = $ids[$i .. [Math]::Min($i + $batchSize - 1, $ids.Count - 1)]
|
||||
$requests = @()
|
||||
for ($j = 0; $j -lt $chunk.Count; $j++) {
|
||||
# Kanonischer Weg: die managedDevices-Navigation des Users. Zuverlaessiger
|
||||
# als $filter=userId eq '..' auf /deviceManagement/managedDevices.
|
||||
$requests += @{ id = [string]($i + $j); method = 'GET'; url = "/users/$($chunk[$j])/managedDevices?`$select=$select" }
|
||||
}
|
||||
$body = @{ requests = $requests } | ConvertTo-Json -Depth 5 -Compress
|
||||
try {
|
||||
$resp = Invoke-MgGraphRequestRetry -Uri 'https://graph.microsoft.com/beta/$batch' -Method POST -Body $body -ContentType 'application/json'
|
||||
foreach ($r in @($resp.responses)) {
|
||||
if ([int]$r.status -ne 200) {
|
||||
if (@($script:GrpDevErrors).Count -lt 3) {
|
||||
$em = $null
|
||||
try { $em = [string]$r.body.error.message } catch {}
|
||||
$script:GrpDevErrors += "HTTP $($r.status)$(if ($em) { ": $em" })"
|
||||
}
|
||||
continue
|
||||
}
|
||||
# Batch-Request-Id -> Index in $ids -> Gruppen-User (fuer UPN/Name-Fallback,
|
||||
# da managedDevice.userPrincipalName bei Graph oft leer ist).
|
||||
$owner = $null
|
||||
$reqIdx = -1; if ([int]::TryParse([string]$r.id, [ref]$reqIdx)) {
|
||||
if ($reqIdx -ge 0 -and $reqIdx -lt $ids.Count) { $owner = $userMap[$ids[$reqIdx]] }
|
||||
}
|
||||
foreach ($d in @($r.body.value)) {
|
||||
$did = [string]$d.id
|
||||
if (-not $did -or $devSeen.ContainsKey($did)) { continue }
|
||||
$devSeen[$did] = $true
|
||||
$upn = if ($d.userPrincipalName) { [string]$d.userPrincipalName } elseif ($owner) { $owner.Upn } else { '' }
|
||||
$udn = if ($d.userDisplayName) { [string]$d.userDisplayName } elseif ($owner) { $owner.DisplayName } else { '' }
|
||||
$items.Add([pscustomobject]@{
|
||||
Id = $did
|
||||
DeviceName = [string]$d.deviceName
|
||||
UserDisplayName = $udn
|
||||
UserPrincipalName = $upn
|
||||
OS = [string]$d.operatingSystem
|
||||
OSVersion = [string]$d.osVersion
|
||||
ComplianceState = [string]$d.complianceState
|
||||
SerialNumber = [string]$d.serialNumber
|
||||
Model = [string]$d.model
|
||||
Manufacturer = [string]$d.manufacturer
|
||||
LastSync = ConvertTo-IsoDate $d.lastSyncDateTime
|
||||
EnrolledDateTime = ConvertTo-IsoDate $d.enrolledDateTime
|
||||
})
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
Write-Host " [GRP-DEV-EXPORT] Batch-Fehler: $($_.Exception.Message)" -ForegroundColor DarkYellow
|
||||
}
|
||||
}
|
||||
|
||||
$sw.Stop()
|
||||
Write-Host " -> $($items.Count) Geraete fuer $($userIds.Count) User, $($sw.ElapsedMilliseconds)ms" -ForegroundColor Green
|
||||
return @{
|
||||
ok = $true
|
||||
groupId = $GroupId
|
||||
groupName = $groupName
|
||||
userCount = $userIds.Count
|
||||
items = @($items.ToArray())
|
||||
count = $items.Count
|
||||
resolvedMs = [int]$sw.ElapsedMilliseconds
|
||||
errors = @($script:GrpDevErrors)
|
||||
}
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# Users
|
||||
# ============================================================
|
||||
@@ -1728,12 +1843,12 @@ function Search-DevicesEndpoint {
|
||||
OS = $d.operatingSystem
|
||||
OSVersion = $d.osVersion
|
||||
ComplianceState = $d.complianceState
|
||||
LastSync = $d.lastSyncDateTime
|
||||
LastSync = ConvertTo-IsoDate $d.lastSyncDateTime
|
||||
ManagementState = $d.managementState
|
||||
SerialNumber = $d.serialNumber
|
||||
Model = $d.model
|
||||
Manufacturer = $d.manufacturer
|
||||
EnrolledDateTime = $d.enrolledDateTime
|
||||
EnrolledDateTime = ConvertTo-IsoDate $d.enrolledDateTime
|
||||
}
|
||||
}
|
||||
return @{ items = $items; count = $items.Count }
|
||||
@@ -1758,12 +1873,12 @@ function Get-DeviceEndpoint {
|
||||
OS = $d.operatingSystem
|
||||
OSVersion = $d.osVersion
|
||||
ComplianceState = $d.complianceState
|
||||
LastSync = $d.lastSyncDateTime
|
||||
LastSync = ConvertTo-IsoDate $d.lastSyncDateTime
|
||||
ManagementState = $d.managementState
|
||||
SerialNumber = $d.serialNumber
|
||||
Model = $d.model
|
||||
Manufacturer = $d.manufacturer
|
||||
EnrolledDateTime = $d.enrolledDateTime
|
||||
EnrolledDateTime = ConvertTo-IsoDate $d.enrolledDateTime
|
||||
Imei = $d.imei
|
||||
WiFiMac = $d.wiFiMacAddress
|
||||
AzureADDeviceId = $d.azureADDeviceId
|
||||
|
||||
Reference in New Issue
Block a user