locked
How can I add members to a new distribution group from a CSV file?

    Question

  • I'd like to import users from a CSV file to a Distribution Group. I've exported the members of an exisiting Distribtution Group to the CSV and I basically want to clone it with a different name. I can't get the Powershell to work...

    I thought it should look like

    Import-Csv -Path D:\ml.csv | ForEach-Object {Add-DistributionGroupMember....this is where I'm lost....
    Orange County District Attorney
    Wednesday, March 18, 2009 5:08 PM

Answers

  • Hey Sandy,

    Try below cmdlet to import from CSV file...

    Import-CSV FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name}

    In filename.csv file should have a column Name and the values must be in anyone of below format to add them as a member...
    GUID distinguished name UPN LegacyExchangeDN Domain\Account Name SMTP Address

    Add-DistributionGroupMember



    Amit Tank | MVP - Exchange | MCITP:EMA MCSA:M | http://ExchangeShare.WordPress.com
    • Proposed as answer by Amit Tank Thursday, March 19, 2009 6:06 AM
    • Marked as answer by Sandy Wood Thursday, March 19, 2009 2:15 PM
    Thursday, March 19, 2009 3:18 AM
  • Exchange Server 2003 does not have this cmdlet or an similar function.  If you want to use PowerShell and you are using Exchange 2003, you could probably use the Quest Active Directory Powershell tools
    http://www.quest.com/powershell/activeroles-server.aspx

    You would need to install the PowerShell and then install the Quest tools. Then take a look at the Add-QADGroupMember cmdlet that Quest provides.
    Jim McBee - Blog - http://mostlyexchange.blogspot.com
    • Marked as answer by Amit Tank Monday, July 6, 2009 2:29 AM
    Saturday, July 4, 2009 11:17 PM

All replies

  • Hey Sandy,

    Try below cmdlet to import from CSV file...

    Import-CSV FileName.csv | ForEach {Add-DistributionGroupMember -Identity "DG Name" -Member $_.Name}

    In filename.csv file should have a column Name and the values must be in anyone of below format to add them as a member...
    GUID distinguished name UPN LegacyExchangeDN Domain\Account Name SMTP Address

    Add-DistributionGroupMember



    Amit Tank | MVP - Exchange | MCITP:EMA MCSA:M | http://ExchangeShare.WordPress.com
    • Proposed as answer by Amit Tank Thursday, March 19, 2009 6:06 AM
    • Marked as answer by Sandy Wood Thursday, March 19, 2009 2:15 PM
    Thursday, March 19, 2009 3:18 AM
  • Good job, Amit

    I tested in the lab

    Step 1: Export Value of the user object you want to add into DG (Distribution Group)

    Csvde -r objectclass=user -d "OU=ExTeam,DC=contoso,DC=com" -l "Name" -f C:\member.txt

    Step 2: Import the file as Amit said

    import-csv C:\member.txt | foreach {add-distributiongroupmember DGName -member $_.Name}

    Step 3: Verify the result via EMC or EMS

    Thursday, March 19, 2009 6:48 AM
  • Thanks again Amit. We gave it a try and it worked perfectly.
    Orange County District Attorney
    • Proposed as answer by mmirzaie Monday, April 11, 2011 6:50 PM
    • Unproposed as answer by mmirzaie Monday, April 11, 2011 6:50 PM
    Thursday, March 19, 2009 2:15 PM
  • My pleasure Sandy... :)
    Amit Tank | MVP - Exchange | MCITP:EMA MCSA:M | http://ExchangeShare.WordPress.com
    Thursday, March 19, 2009 2:19 PM
  • Hi Amit,
    how can i do this on exchange 2003?
    I now that add-distributiongroupmember - is exchange 2007 cmdlet and is don't work on 2003.
    10x
    Saturday, July 4, 2009 8:19 AM
  • Exchange Server 2003 does not have this cmdlet or an similar function.  If you want to use PowerShell and you are using Exchange 2003, you could probably use the Quest Active Directory Powershell tools
    http://www.quest.com/powershell/activeroles-server.aspx

    You would need to install the PowerShell and then install the Quest tools. Then take a look at the Add-QADGroupMember cmdlet that Quest provides.
    Jim McBee - Blog - http://mostlyexchange.blogspot.com
    • Marked as answer by Amit Tank Monday, July 6, 2009 2:29 AM
    Saturday, July 4, 2009 11:17 PM
  • WOW

    Jim thx, it work Perfect!!! :)

    Thanks
    Sunday, July 5, 2009 5:03 PM
  • The Quest tools are great.  I use them on all of my E2K3 servers (that I wish I could migrate to E2K7)  :-)

    Jim McBee - Blog - http://mostlyexchange.blogspot.com
    Sunday, July 5, 2009 8:39 PM
  • Exchange Server 2003 does not have this cmdlet or an similar function.  If you want to use PowerShell and you are using Exchange 2003, you could probably use the Quest Active Directory Powershell tools
    http://www.quest.com/powershell/activeroles-server.aspx

    You would need to install the PowerShell and then install the Quest tools. Then take a look at the Add-QADGroupMember cmdlet that Quest provides.
    Jim McBee - Blog - http://mostlyexchange.blogspot.com


    Hi Amit,

    I have 100+ DL's & need to add 15-30Users a memeber of it, can you please let me know how do i achieve this with VB script & a input file as csv

    The CSV file will be GroupName, DN,GroupType, Memebers (User Sam A/c) with clon seperated.

    Thanks

    Rocks

    Monday, July 6, 2009 11:24 AM
  • Amit, this has helped me greatly, thank you.
    Monday, October 15, 2012 8:07 PM
  • What if you wanted to export all users with relation to their group membership not just members of one group at a time?

    yaro

    Sunday, March 10, 2013 2:37 PM
  • Hey Amit,

    found this blog regarding bulk users mgmt on exchange online with exchange online mgmt shell.

    is this cmdlet usefull on exchange online (2013) also?

    We need to carry out following tasks for bulk users management on exchange online in management shell :

     

    1. External users to be rejected to send mail to these dist groups,
    2. Specific users will be members of specific dist. Groups,
    3. Specific users will be able to send mails to specific dist groups,
    4. To verify recipients for a specific dist group,
    5. To hide dist groups on global address list,
    6. to bulk add users as members of a dist group.
    7. format / template  required for the above management tasks(for bulk management)

    I  tried  running cmdlet   “Import-Csv <Path>| foreach {Add-DistributionGroupMember -Identity <Distribution Group Name> -Member $_.identity} “   & “import-csv file.csv | ${set-distributiongroup $_.DG -RejectMessagesFromSendersOrMembers $_.Users} “ in elevated windows powershell. but got an error " Cannot validate argument on parameter 'Member'. The argument is null. Supply a non-null argument and try the command again. "  

     

    i could not get the null value part neither could understand the parameter required in this regard.. we need to know what would be the parameters in these cmdlets.

    what i understand is for managing bulk users for above tasks, we need to run scripts on exchange online(2013).

    if you can help us out with scripts  to add bulk users as members to dist groups & also set reject bulk users to block them to dist groups, that will be gr8..

    also required is csv file format/template in these regards.

      this is most urgent..

    Thanks in advance,

    ..Ajit


    • Edited by ajitcs Thursday, August 14, 2014 12:02 PM addition to the requirement
    Thursday, August 14, 2014 12:00 PM
  • Yes you can do this by this PowerShell script.

    Just add all Group names and user you wanted to add in this group in csv and run this script.

    http://mysolutioncafe.blogspot.in/2015/12/add-multiple-users-to-multiple-groups.html

    import-module activedirectory
    $list = import-csv "C:\AD\1234.csv"
    Foreach($user in $list){      
        add-adgroupmember -identity $user.Group -member (Get-ADUser $user.Accountname)
    }

     

    dilip patel

    Friday, December 25, 2015 8:30 AM