?
Solved

Import Distribution Lists from CSV into Exchange 2010

Posted on 2012-03-12
6
Medium Priority
?
9,438 Views
2 Endorsements
Last Modified: 2012-03-12
Hello,

I have a CSV file containing entries I would like to add to an Exchange Distribution List using Powershell. I have learned how to create a distribution list using Powershell, but still not sure how to add a list of entries into the Distribution List via Powershell.

I can create a distribution list like this and it works:

New-DistributionGroup -name "ITDepartment" -IgnoreNamingPolicy

Now that I have a Distribution Group, how do I add members into it using Powershell? Here is the structure of my CSV file, and it is located on my c: drive:

<Email>,<FullName>

How can I use PowerShell to add a line entry from this CSV file into the Distribution List I created? Then, how would I use PowerShell to add all entries from the CSV file?

Thanks for your help.

John
2
Comment
Question by:jhieb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 42

Accepted Solution

by:
Adam Brown earned 2000 total points
ID: 37710644
You would utilize the import-csv cmdlet and the add-distributiongroupmember cmdlets together to do this. Adding all the entries is a lot easier than just adding a single line from the CSV, so I'll just give you that one :D

import-csv <csv filename> | foreach {add-distributiongroupmember "ITDepartment" -member $_.email}

Open in new window


Basically, the import-csv cmdlet reads out each entry in the CSV file. The | character is a pipeline that pushes what is read from the import-csv cmdlet into whatever is next. Foreach tells the system that for each line read from the CSV file, do the following. Then we use add-distributiongroupmember against the ITDepartment List and add the member by using the pipelined email variable. $_.<attribute> is what does that.
0
 
LVL 1

Author Comment

by:jhieb
ID: 37710715
Thanks. I ran the command and it seems to have worked, but my members did not show up in the ITDepartment list. Do I need to delare column headers or something so that PowerShell knows the format of the CSV file? I don't understand how PowerShell will know which values to use, and this part of your example confuses me:

{add-distributiongroupmember "ITDepartment" -member $_.email}

How does this tell PS which columns are what?

Attached, is a sample CSV file.

Thanks.
dlist.txt
0
 
LVL 42

Assisted Solution

by:Adam Brown
Adam Brown earned 2000 total points
ID: 37710725
Yes, you do have to have a header line for the CSV to be readable.
add this to the top line of your CSV:

name,email
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Author Comment

by:jhieb
ID: 37710794
Thanks. That worked and I was able to add two dlist members to the list. I get an error with this command. Do you know how to get rid of this error?



[PS] C:\>import-csv c:\temp\dlist.txt | foreach {add-distributiongroupmember "ITDepartment" -member $_.email}
Cannot validate argument on parameter 'Member'. The argument is null. Supply a non-null argument and try the command ag
ain.
    + CategoryInfo          : InvalidData: (:) [Add-DistributionGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DistributionGroupMember

Cannot validate argument on parameter 'Member'. The argument is null. Supply a non-null argument and try the command ag
ain.
    + CategoryInfo          : InvalidData: (:) [Add-DistributionGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DistributionGroupMember

[PS] C:\>
0
 
LVL 42

Expert Comment

by:Adam Brown
ID: 37710806
That means that the value read in from the CSV file didn't have any data in it. If you have any empty lines at the end of your CSV file, or if any line has a name but no email address it will do that.
0
 
LVL 1

Author Closing Comment

by:jhieb
ID: 37710854
I thought I needed a carriage return after each entry. It looks like all I need is a line entry. Thank you for the help. This works great!
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question