Description

Need script for removing bulk users from multiple group

On request to:

https://gallery.technet.microsoft.com/scriptcenter/site/requests/Bulk-Add-Multiple-User-Accounts-To-Multiple-Groups-From-Text-File-8d72e0f0

 

-Import from CSV

-Read through each line , split multiple memberships to work with

-Add/Remove Users

PowerShell
Edit|Remove
$UsersAndGroups = import-csv "C:\UsersToAdd.csv" 
 
Foreach($User in $UsersAndGroups) 
 { 
  $UserToAddRemove = $User.User 
  $UserGroups      = $User.Groups -split ";" 
   
  foreach($GroupNameToModify in $UserGroups) 
   { 
    #Uncomment/Comment the desired option, try the Whatif option before. 
    Add-ADGroupMember    $GroupNameToModify -Members $UserAddToRemove -Confirm:$false # -WhatIf 
    #Remove-ADGroupMember $GroupNameToModify -Members $UserAdTodRemove -Confirm:$false # -WhatIf 
   } 
 } 
 
 #PFA a CSV File Sample 
 <# 
  Groups                 User 
 GroupName1;GroupName3  SamAccounName1 
 GroupName2;GroupName5  SamAccount2 
 #>