Microsoft Graph Remove owner of Azure Group delete the user

Copper Contributor



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. 


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


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

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

$Remove = (Invoke-RestMethod "$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. 



2 Replies
best response confirmed by Aleksander780 (Copper Contributor)
At the very least, try escaping $ref, as it's not an actual variable.
Just "escaping" did not help in my case, but it thrown different error which I have resolved by make URI as variable.

$URL = "$groupID/owners/$userID/`$ref"
$Remove = (Invoke-RestMethod -URI $URL -Headers $authHeader -Method DELETE -StatusCodeVariable:StatusCode)

Now it works as it should.