The Remove-MgGroupMemberByRef command of the Graph PowerShell SDK doesn't work for me, even though I already have the latest graph groups module, not sure if this is an unknown issue.
As an alternative solution, I use PowerShell online to call the API endpoint directly, and it works fine for me. Reference:
$clientID = 'client id'
$secretKey = 'client secret'
$tenantID = 'tenant id'
$authUrl = "https://login.microsoftonline.com/" + $tenantID + "/oauth2/v2.0/token/"
$body = @{
"scope" = "https://graph.microsoft.com/.default";
"grant_type" = "client_credentials";
"client_id" = $ClientID
"client_secret" = $secretKey
}
$authToken = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
$url = "https://graph.microsoft.com/v1.0/groups/{group id}/members/{member object id}/`$ref"
$headers = @{
"Authorization" = "Bearer $($authToken.access_token)"
"Content-type" = "application/json"
}
Invoke-RestMethod -Uri $url -Headers $headers -Method Delete
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.