SOLVED

Microsoft Graph Remove owner of Azure Group delete the user

New Contributor

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. 

 

 

2 Replies
best response confirmed by Aleksander780 (New Contributor)
Solution
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 = "https://graph.microsoft.com/v1.0/groups/$groupID/owners/$userID/`$ref"
$Remove = (Invoke-RestMethod -URI $URL -Headers $authHeader -Method DELETE -StatusCodeVariable:StatusCode)

Now it works as it should.