Forum Discussion

Aleksander780's avatar
Aleksander780
Copper Contributor
Dec 08, 2022

Microsoft Graph Remove owner of Azure Group delete the user

Hello,

 

I have problem where I would like to remove owner of the group, but instead of the user is completely removed. I am using Azure function HTTP triggered as PowerShell with HTTPs RestMethod. 

Payload:

{
"groupID": "{group_id}",
"userID": "{user_id}"
}
 

Code:

$authHeader = @{
'Authorization' = 'Bearer ' + $accessToken
}

$groupID = $Request.Body.groupID
$userID = $Request.Body.userID

$Remove = (Invoke-RestMethod "https://graph.microsoft.com/v1.0/groups/$groupID/owners/$userID/$ref" -Headers $authHeader -Method DELETE -StatusCodeVariable:StatusCode)

Push-OutputBinding -Name Response -Clobber -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = $Remove
})

 

There is no error, code returned is 204, so as it should, everything is fine, beside the fact that user is deleted completely from the tenant. 

When I ran it from Graph Explorer, everything works perfectly fine as it supposed to.  Any advice?

Thanks, in advance. 

 

 

  • At the very least, try escaping $ref, as it's not an actual variable.

Resources