Share via

Import CSV file into Office 365 distribution group.

Anonymous
2019-08-09T14:41:17+00:00

Hello, 

I am trying to import a CSV file to a distribuion list through powershell. 

Here is the problem I am running into. 

Here is a generic version of what the CSV entries look like:

Where is my mistake, and how should the script read?

Thank you!

Microsoft 365 and Office | Subscription, account, billing | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

  1. Anonymous
    2019-08-09T16:27:27+00:00

    Hello Bryce Knezovich,

    From your post, in general, when using New-DistributionGroup command, I would suggest you may use the parameters this command provided, like -Name, -Alias, -Type, otherwise PowerShell will not recognize. You may also use ForEach-Object than foreach. It is also recommended to modify the column headers in CSV file so they can be called by PowerShell properly.

    If you’d like to create distribution group for each entry in CSV file, you may refer to:

    Import-CSV “C:\Users\Administrator\Desktop\parents.csv | Foreach-Object { New-DistributionGroup –Name $_.Name –Alias $_.Alias –Type $_.Type }

     

    Or if you want to add these entries to an existing distribution group, you may use:

    Import-CSV "C:\Users\Administrator\Desktop\parents.csv" | Foreach-Object { Add-DistributionGroupMember -Identity "T estDL2" -Member $_.Member }

    If it isn’t an existing group, you may create it first, then add members:

    New-DistributionGroup –Name “TestDL2” –Alias “testdl2

    Import-CSV "C:\Users\Administrator\Desktop\parents.csv" | Foreach-Object { Add-DistributionGroupMember -Identity "TestDL2" -Member $_.Member }

    Here are some articles for your reference:

    ForEach

    ForEach-Object

    New-DistributionGroup

    Add-DistributionGroupMember

    Best Regards,

    Anna

    Was this answer helpful?

    6 people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-08-14T01:46:46+00:00

    Hello Bryce,

    From the error message it says that the email you provided is not recognized in your Office 365 tenant. The command “New-DistributionGroup” helps customer creating an org-wide distribution group, when adding group members, these members should be the objects existed in your organization. May I know whether the email addresses under CSV column “Member” are all existed in organization? If not, use email address existed in your organization to see if command works. Any result, welcome back to share with us. :-)

    Best Regards,

    Anna

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-08-13T18:37:33+00:00

    Thank you for your reply Anna. 

    I was able to create the distribution group:

    I then edited the csv columns to reflect how yours were configured, and then import the data, and this is what I ran into:

    Thank you

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2019-08-10T21:39:06+00:00

    Hello Bryce Knezovich,

    Please do not hesitate to contact me if you need any assistance.

    Best Regards,

    Anna

    Was this answer helpful?

    0 comments No comments
  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more