Avatar of jhieb
jhieb
Flag for United States of America asked on

Import Distribution Lists from CSV into Exchange 2010

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
ExchangePowershellActive Directory

Avatar of undefined
Last Comment
jhieb

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Adam Brown

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jhieb

ASKER
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
SOLUTION
Adam Brown

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
jhieb

ASKER
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:\>
Adam Brown

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.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
jhieb

ASKER
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!