0

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.

1 Answer 1

1

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 } } 
Sign up to request clarification or add additional context in comments.

Comments