diverse anpassungen

This commit is contained in:
2026-06-17 09:41:43 +01:00
parent eeabb1db31
commit c860ea9a10
9 changed files with 429 additions and 41 deletions
+94 -1
View File
@@ -55,6 +55,14 @@ function Invoke-ApiHandler {
return Get-GroupMembersEndpoint -GroupId $matches[1]
}
if ($Method -eq "POST" -and $Path -match "^/api/groups/([^/]+)/members$") {
return Add-GroupMembersEndpoint -GroupId $matches[1] -Body $Body
}
if ($Method -eq "DELETE" -and $Path -match "^/api/groups/([^/]+)/members/([^/]+)$") {
return Remove-GroupMemberEndpoint -GroupId $matches[1] -UserId $matches[2]
}
if ($Method -eq "GET" -and $Path -match "^/api/apps/([^/]+)/details$") {
return Get-AppDetailsEndpoint -AppId $matches[1]
}
@@ -1191,6 +1199,91 @@ function Get-GroupMembersEndpoint {
return @{ items = $items; count = $items.Count }
}
function Add-GroupMembersEndpoint {
param([string]$GroupId, $Body)
$err = Test-Connected
if ($err) { return $err }
if ([string]::IsNullOrWhiteSpace($GroupId)) {
return @{ __status = 400; error = "GroupId fehlt" }
}
if (-not $Body) {
return @{ __status = 400; error = "Request-Body fehlt" }
}
$ids = @()
if ($Body.userIds) {
$ids = @($Body.userIds | ForEach-Object { [string]$_ } | Where-Object { $_ })
} elseif ($Body.userId) {
$ids = @([string]$Body.userId)
}
if ($ids.Count -eq 0) {
return @{ __status = 400; error = "userId oder userIds fehlt im Body" }
}
$success = 0; $errors = 0
$results = @()
foreach ($uid in $ids) {
try {
Add-GraphMember -GroupId $GroupId -DirectoryObjectId $uid
$success++
$results += @{ userId = $uid; status = "Success" }
Write-Host " [ADD MEMBER] GroupId=$GroupId UserId=$uid OK" -ForegroundColor Green
} catch {
$details = Get-GraphErrorFriendly -ErrorRecord $_
if ($details.IsWarning) {
$success++
$results += @{ userId = $uid; status = "AlreadyMember"; message = $details.Friendly }
Write-Host " [ADD MEMBER] $uid bereits Mitglied in $GroupId" -ForegroundColor DarkGreen
} else {
$errors++
$results += @{ userId = $uid; status = "Error"; code = $details.Code; message = $details.Friendly }
Write-Host " [ADD MEMBER] FAIL $uid -> $GroupId [$($details.Code)] $($details.Friendly)" -ForegroundColor Red
}
}
}
if ($script:State.GroupMembers.ContainsKey($GroupId)) {
$script:State.GroupMembers.Remove($GroupId)
}
return @{
ok = ($errors -eq 0)
success = [int]$success
errors = [int]$errors
total = [int]$ids.Count
results = $results
}
}
function Remove-GroupMemberEndpoint {
param([string]$GroupId, [string]$UserId)
$err = Test-Connected
if ($err) { return $err }
if ([string]::IsNullOrWhiteSpace($GroupId) -or [string]::IsNullOrWhiteSpace($UserId)) {
return @{ __status = 400; error = "GroupId und UserId erforderlich" }
}
try {
$null = Invoke-MgGraphRequest `
-Uri "https://graph.microsoft.com/v1.0/groups/$GroupId/members/$UserId/`$ref" `
-Method DELETE
Write-Host " [REMOVE MEMBER] GroupId=$GroupId UserId=$UserId OK" -ForegroundColor Green
} catch {
$details = Get-GraphErrorFriendly -ErrorRecord $_
$status = if ($details.Code -like '*404*') { 404 } elseif ($details.Code -like '*403*') { 403 } else { 500 }
Write-Host " [REMOVE MEMBER] FAIL [$($details.Code)] $($details.Friendly)" -ForegroundColor Red
return @{ __status = $status; error = $details.Friendly; code = $details.Code }
}
if ($script:State.GroupMembers.ContainsKey($GroupId)) {
$script:State.GroupMembers.Remove($GroupId)
}
return @{ ok = $true; groupId = $GroupId; userId = $UserId }
}
function Search-GroupsEndpoint {
param($Query)
$err = Test-Connected
@@ -2689,7 +2782,7 @@ footer code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;bac
</details>
<footer>
Intune App-Zuweisungs-Manager &middot; Web Edition <code>v$(_enc $script:ToolVersion)</code> &middot; Build <code>$(_enc $script:BuildStamp)</code>
Intune Manager &middot; Web Edition <code>v$(_enc $script:ToolVersion)</code> &middot; Build <code>$(_enc $script:BuildStamp)</code>
</footer>
</div>
</body>