What is the fastest way to remove all users from an Azure AD group in PowerShell? I am currently using
$deleteThem = Get-MsolGroupMember -GroupObjectId $groupId -All
foreach ($user in $deleteThem) {
Remove-MsolGroupMember -GroupObjectId $groupId -GroupMemberObjectId $user.ObjectId
}
but this is painfully slow. I need to retain the group and group id though. Any ideas?
As mentioned by Ash in comments section , Using Remove-AzADGroupMember is faster than Remove-MsolGroupMember.
I ran the below script for deleting users in a group by just providing the Group name.
Note : In credentials prompt box, provide the admin id of the tenant and password. If there are lot of users in the group then it is expected to take some time.