Remove bulk users from a Group(multi domain environment)

Welcome Forums General PowerShell Q&A Remove bulk users from a Group(multi domain environment)

This topic contains 5 replies, has 2 voices, and was last updated by

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #121858

    Participant
    Points: 15
    Rank: Member

    I want remove bulk users from an AD group, and the below command is working me, if group and users are in same domain, since our AD environment has one forest with three child domains, this command fails if the group or users were in different domain, I tried using $DC from group Domain/Domain Controller, User Domain/Domain Controller and global catalog, but it fails. could anyone help on this. Thanks in advance.

    Remove-ADGroupMember -Identity $GroupName -Server $DC -Members $user -Confirm:$false

  • #121878

    Participant
    Points: 114
    Helping Hand
    Rank: Participant

    What's the error that you are getting? Why does it fail?

  • #121891

    Participant
    Points: 15
    Rank: Member

    I received below error in the provided scenarios:

    when using global catalog as $DC
    ERROR: remove-ADGroupMember : The server is unwilling to process the request

    when using the Group domain as $DC
    ERROR: remove-ADGroupMember : Cannot find an object with identity: 'UserName' under: 'Group domain'.

    when using the user domain as $DC
    ERROR: remove-ADGroupMember : Cannot find an object with identity: 'GroupName' under: 'User Domain'.

  • #121903

    Participant
    Points: 114
    Helping Hand
    Rank: Participant

    What happens if you try to save the objects from their corresponding Domains to variables first, before trying to remove users from a group?

    For example:

    $User = Get-ADUser -Server user.domain
    $Group = Get-ADGroup -Server group.domain
    Remove-ADGroupMember -Identity $Group -Members $User
    
  • #121918

    Participant
    Points: 15
    Rank: Member

    Great... It works...

    Thanks a lot

  • #122087

    Participant
    Points: 114
    Helping Hand
    Rank: Participant

    No worries! Glad to be of help.

You must be logged in to reply to this topic.