FunctionsPublic/Add-GraphOwnerToGroup.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
function Add-GraphOwnerToGroup { param( [psobject]$accessToken, [string]$groupID, [string]$userID ) # # Add Owner to group # $sendBody = @{ "@odata.id"="https://graph.microsoft.com/v1.0/users/$($userID)" } | ConvertTo-Json $responseBody = Invoke-RestMethod ` -Uri "https://graph.microsoft.com/v1.0/groups/$($groupID)/owners/`$ref" ` -Headers @{"Authorization" = "Bearer $($accessToken.AccessTokenCredential.GetNetworkCredential().password)"} ` -Body $sendBody ` -ContentType "application/json" ` -Method POST $jsonResponse = $responseBody | ConvertTo-JSON $addOwnerResult = ConvertFrom-Json -InputObject $jsonResponse return $addOwnerResult } |