locked
Made one group to another group member in AD RRS feed

  • Question

  • I have DL (Distribution List or group) name like ***mailsending in Active directory, which needs to be made memberof another DL like "zzzmaileurope".

    I need to query to AD for searching group or DL name ***mailsending and then made this group member of another group or DL name zzzmaileurope.

    Monday, April 1, 2013 2:15 PM

Answers

  • $group = Get-ADGroup -Filter {Name -like "*mailsending"} | Select-Object -ExpandProperty DistinguishedName
    
    Add-ADGroupMember -Identity $group

    Now if you have multiple groups that are like ***mailsending, then $groups will contain all of those groups, so if you know the exact name of the group, then replace -Filter {Name -like "*mailsending" } with -Filter { Name -eq "mailsending" }

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 2:26 PM
  • Thanks but one thing here.

    If i understand correctly your script then it says that 

    $group= get-adgroup -filter {name-eq "***mailsending"}  :: it will query to AD and find the exact group name

    | Select-object -ExpandProperty DistinguishedName  :: It will expand the group(***mailsending) property with Distinguishedname

    Now

    Add-ADgroupMember -identity $group  :: This command add the groupmembershitp of Identity group which is with variable $group.

    Then where can I see or add other group name to add here ? Please guide

    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 2:52 PM
  • $group = Get-ADGroup -Filter {Name -eq '***mailsending'} | Select-Object -ExpandProperty DistinguishedName
    
    Add-ADGroupMember -Identity $group

    Raj...if you groupname is ***mailsending  and you dont want the *** not to be treated as wildcard....you can use interpolation ...single quotes


    Thanks Azam When you see answers please Mark as Answer if Helpful..vote as helpful.


    • Edited by mohdazam89 Monday, April 1, 2013 4:17 PM
    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 4:16 PM
  • No, you were right.

    I need to add one group to another group member. That is the only requirement I have.


    $groupToAdd = "MyGroup" # Exact name of group you are looking for with Get-ADGroup
    Get-ADGroup -Filter { Name -eq $groupToAdd } | Select-Object -ExpandProperty DistinguishedName | Add-ADGroupMember -Identity "GroupToAddTo" -Members $_

    That should do everything you

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.



    • Edited by clayman2 Monday, April 1, 2013 4:26 PM
    • Proposed as answer by Yan Li_ Tuesday, April 2, 2013 2:44 AM
    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 4:25 PM

All replies

  • $group = Get-ADGroup -Filter {Name -like "*mailsending"} | Select-Object -ExpandProperty DistinguishedName
    
    Add-ADGroupMember -Identity $group

    Now if you have multiple groups that are like ***mailsending, then $groups will contain all of those groups, so if you know the exact name of the group, then replace -Filter {Name -like "*mailsending" } with -Filter { Name -eq "mailsending" }

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 2:26 PM
  • Thanks but one thing here.

    If i understand correctly your script then it says that 

    $group= get-adgroup -filter {name-eq "***mailsending"}  :: it will query to AD and find the exact group name

    | Select-object -ExpandProperty DistinguishedName  :: It will expand the group(***mailsending) property with Distinguishedname

    Now

    Add-ADgroupMember -identity $group  :: This command add the groupmembershitp of Identity group which is with variable $group.

    Then where can I see or add other group name to add here ? Please guide

    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 2:52 PM
  • OK, I may have misunderstood your exact requirements. You want to query AD for multiple groups and add them to one or many groups?

    $group= get-adgroup -filter {name-eq "***mailsending"}  :: it will query to AD and find the exact group name

    That will find the group with the name of ***mailsending, I never seen a group named like that, so I assume the *** are for wildcards? If you are trying to search for multiple groups using wild cards, then you need to change -eq to -like, as -eq looks for an exact match on the string you specify.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    Monday, April 1, 2013 3:16 PM
  • No, you were right.

    I need to add one group to another group member. That is the only requirement I have.

    Monday, April 1, 2013 4:06 PM
  • $group = Get-ADGroup -Filter {Name -eq '***mailsending'} | Select-Object -ExpandProperty DistinguishedName
    
    Add-ADGroupMember -Identity $group

    Raj...if you groupname is ***mailsending  and you dont want the *** not to be treated as wildcard....you can use interpolation ...single quotes


    Thanks Azam When you see answers please Mark as Answer if Helpful..vote as helpful.


    • Edited by mohdazam89 Monday, April 1, 2013 4:17 PM
    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 4:16 PM
  • No, you were right.

    I need to add one group to another group member. That is the only requirement I have.


    $groupToAdd = "MyGroup" # Exact name of group you are looking for with Get-ADGroup
    Get-ADGroup -Filter { Name -eq $groupToAdd } | Select-Object -ExpandProperty DistinguishedName | Add-ADGroupMember -Identity "GroupToAddTo" -Members $_

    That should do everything you

    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.



    • Edited by clayman2 Monday, April 1, 2013 4:26 PM
    • Proposed as answer by Yan Li_ Tuesday, April 2, 2013 2:44 AM
    • Marked as answer by Mr. Raj Tuesday, April 2, 2013 6:18 PM
    Monday, April 1, 2013 4:25 PM