How can add all member of a Dynamic Distribution group to a new Security Group

Mohammad Ajorlou 41 Reputation points
2021-01-04T12:18:46.54+00:00

Hi everyone

We have a dynamic distribution group in our Exchange Server, I need to create a new Security Group in Active Directory and add all members of the dynamic distribution group to this Security Group (for other purpose), I think PowerShell script on cmdlet command shall be required to export members of dynamic distribution group and to add to security group but I don't know how to execute this action !?

kindly help me

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
6,455 questions
Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,606 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 147.6K Reputation points MVP
    2021-01-04T13:29:26.063+00:00

    You can view all the members this way:
    https://video2.skills-academy.com/en-us/exchange/recipients/dynamic-distribution-groups/view-dynamic-distribution-group-members?view=exchserver-2019

    Example:

    $group = "Full Time Employees"  
    Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup $group).RecipientFilter  
    

    Now that you have the group - you can output the SAMAccountName

    $Users = (Get-Recipient -RecipientPreviewFilter (Get-DynamicDistributionGroup $group).RecipientFilter).SamAccountName   
    

    $users should show all the SAMAccountNames of the group members Use that to add to the new group ( I am assuming this is an on-prem AD group)

    Use: Add-ADGroupMember

    $users | % {Add-ADGroupMember -identity SecurityGroup -members $_ }  
    

    https://video2.skills-academy.com/en-us/powershell/module/addsadministration/add-adgroupmember?view=win10-ps

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.