How to remove multiple members from Multiple groups in Office 365

Hi Team,

How to remove multiple members from Multiple groups in Office 365, i am using the below script to remove multiple users from AD groups, can anyone suggest what modificaton i need do to remove multiple members from Multiple groups in Office 365

$Members= ForEach ($member in (Import-csv Gm.csv))
{
    $Groups = Get-ADGroup -Filter {Name -like "SG--*"}
    $Members = $Member.'samaccountname'
    Get-ADUser -Filter "samaccountname -eq '$Members'"|
    % { Remove-ADPrincipalGroupMembership -Identity $Groups -Members $Members -Confirm} -ErrorAction Stop 
}

Thanks
Vel

I used your headline as a google search and the following come up as the first hit:

Even if it does not fit your requirement perfectly it should give you a push to the right direction. :wink:

For something like this you may want split your script into two separate tools. One for grabbing the user accounts and building an array. Then have the second tool pull that output from the first tool to remove the list users from the multiple groups.