I have a .csv file with the group names and the SAM of the users I want to delete from the 10 groups.
How does this work? I am a PowerShell beginner.
Save the user list as csv and use something like
$users = import-csv C:\csvpath\users.csv Foreach ($user in $users){ Remove-adgroupmember -identity "groupname1" -members $user.username -Confirm:$false Remove-adgroupmember -identity "groupname2" -members $user.username -Confirm:$false } You could of course also get the groupnames from another csv to get a cleaner code
$users = import-csv C:\csvpath\users.csv $groups = import-csv C:\csvpath\groups.csv Foreach ($user in $users){ Foreach ($group in $groups) { Remove-adgroupmember -identity $group.name -members $user.username -Confirm:$false } }