Link to home
Start Free TrialLog in
Avatar of Roccat
RoccatFlag for United States of America

asked on

remove user from list of groups

I am looking to remove a user from a list of groups. He may be part of a few of them. But if the user is not part of one of the groups the script seems to stop.  I would like to attempt to remove the user from all of the groups even if the user is not part of them.  

$script:groups = @("group1", "group2","group3")
foreach ($adgroups in $groups) { remove-adgroupmember $adgroups –members $a -confirm:$false }

If it makes it any easier all of the groups are part of a parent group. So group2 and group3 are part of group1.  I dont know if there is a way to just remove a user from the parent group and all sub groups.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roccat

ASKER

Thank you!