In this post we will describe an easy and convenient way to empty an Azure AD group from its members.
We often need to empty an Azure AD group and the manual way to do so, by exporting the members and running a specific process, is time consuming and not efficient. We can achieve the above by running a simple PowerShell script, which is shown below.
Connect-AzureAD
$group = Get-AzureADGroup -SearchString "ThisIsYourGroup"
# depending on the user members users or devices select the appropriate command below
$devices = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | where {$_.ObjectType -eq 'Device'}
# $users = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true | where {$_.ObjectType -eq 'User'}
foreach($device in $devices){
Remove-AzureADGroupMember -ObjectId $group.ObjectId -MemberId $device.objectId
}