Hi @松田 大知
As we discussed in this thread, the api documentation doesn't seem to provide a PowerShell command to remove group members, there is a similar issue on GitHub.
As an alternative solution, you can refer to this script to remove group members:
$clientID = " "
$secretKey = " "
$tenantID = " "
$username = " "
$password = " "
$authUrl = "https://login.microsoftonline.com/" + $tenantID + "/oauth2/v2.0/token/"
$body = @{
"scope" = "https://graph.microsoft.com/.default";
"grant_type" = "password";
"client_id" = $ClientID;
"client_secret" = $secretKey;
"username" = $username;
"password" = $password
}
$authToken = Invoke-RestMethod -Uri $authUrl –Method POST -Body $body
$url = "https://graph.microsoft.com/v1.0/groups/{group-id}/members/{directory-object-id}/`$ref"
$headers = @{
"Authorization" = "Bearer $($authToken.access_token)"
}
Invoke-RestMethod -Uri $url -Headers $headers -Method DELETE
Of course, you can also add user objects to a different group:
Import-Module Microsoft.Graph.Groups
$params = @{
"@odata.id" = "https://graph.microsoft.com/v1.0/directoryObjects/{id}"
}
New-MgGroupMemberByRef -GroupId $groupId -BodyParameter $params
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.