How can I remove a user from a set of specific groups?

Hi,

I'm trying to remove a user from a set of specific groups.

I have found plenty of articles on how to remove a user from all groups.

e.g

I want to say :

Remove Bob from Group1,Group2 and Group3.

Should I create an array with the group names, then and loop through it?

Thanks

September 5th, 2015 9:00am

You can create an array, but then use the -Remove parameter of Set-ADUser to remove them in one step. For example:

$Groups = @("cn=Group1,ou=West,dc=MyDomain,dc=com", "cn=Group2,ou=West,dc=MyDomain,dc=com", "cn=Group3,ou=West,dc=MyDomain,dc=com")
Set-ADUser -Identity "jsmith" -Remove @{memberOf=$Groups}

This requires the distinguished names of the groups.
Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 10:49am

Hi thanks for the reply

I managed to do it by using this method. 

$Groups = @("all_users","all_users1");

ForEach($group in $Groups)
{
Remove-ADGroupMember -identity $group -member $user;
}



  • Edited by midi25 13 hours 32 minutes ago
September 5th, 2015 1:20pm

Hi thanks for the reply

I managed to do it by using this method. 

$Groups = @("all_users","all_users1");

ForEach($group in $Groups)
{
Remove-ADGroupMember -identity $group -member $user;
}



  • Edited by midi25 13 hours 38 minutes ago
Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 1:20pm

Hi thanks for the reply

I managed to do it by using this method. 

$Groups = @("all_users","all_users1");

ForEach($group in $Groups)
{
Remove-ADGroupMember -identity $group -member $user;
}



  • Edited by midi25 Saturday, September 05, 2015 5:29 PM
September 5th, 2015 5:18pm

Hi thanks for the reply

I managed to do it by using this method. 

$Groups = @("all_users","all_users1");

ForEach($group in $Groups)
{
Remove-ADGroupMember -identity $group -member $user;
}



Free Windows Admin Tool Kit Click here and download it now
September 5th, 2015 5:18pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics