How to recursive import to security group all members from Universal DG

Tagged: 

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of maxcoder maxcoder 1 month ago.

  • Author
    Posts
  • #56864
    Profile photo of maxcoder
    maxcoder
    Participant

    How can I to import all the members of a universal distribution group in Active Directory into a security group? in many cases there are nested distibution groups. How can I get the members of each nested group?
    I mean I will get recursive Group Membership of Distribution Group and all members import to the SG

    Here is my command :

    Get-ADGroupMember -Identity distributiongroup | ForEach-Object { Add-ADGroupMember -Identity securitygroup -Members $_ }

    Error Message:

        Add-ADGroupMember : A global group cannot have a universal group as a member
        At line:1 char:124
        + Get-ADGroupMember -Identity "distribution_group" | ForEach-Object { Add-ADGroupMember < <<<  -Identity "SG_users" 
        -Members $_ }
            + CategoryInfo          : NotSpecified: (SG_users:ADGroup) [Add-ADGroupMember], ADException
            + FullyQualifiedErrorId : A global group cannot have a universal group as a member,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember
  • #56869
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    There isn't a need to do a foreach. Add-ADGroupMember has a Members property that is expecting a collection, so try this:

    Add-ADGroupMember -Identity SECURITYGROUP -Members (Get-ADGroupMember -Identity DISTRIBUTIONGROUP)
    

    If there is a Universal Group nested in the Distribution Group, then the error is accurate.

  • #56879
    Profile photo of maxcoder
    maxcoder
    Participant

    I am getting same error message Add-ADGroupMember : A global group cannot have a universal group as a member

You must be logged in to reply to this topic.