Solved

Creating Distribution Groups in PS

Posted on 2016-11-22
2
64 Views
Last Modified: 2016-11-30
I have been using this with great success but now I am coming up on some very large DGs that I need to create and was wondering what the best way to create the DL if I have all the email addresses in a CSV.  Could someonw point me in the right direction?

New-DistributionGroup -Name "Intelerad Group" -Members chris@contoso.com,michelle@contoso.com,laura@contoso.com,julia@contoso.com
0
Comment
Question by:SDISupport
[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
2 Comments
 
LVL 19

Assisted Solution

by:Peter Hutchison
Peter Hutchison earned 250 total points
ID: 41898712
You could use an simple import routine from a file and add the members from the CSV:
Param($file)
$userlist = Import-CSV $file
$groupname = "My group"

Foreach ($user in $userlist) {
  Add-DistributionGroupMember -Identity $groupName -Member ($user.Identity)
}
0
 
LVL 37

Accepted Solution

by:
Mahesh earned 250 total points
ID: 41900116
Try below

# Create csv file with Email as header and add all members email address underneath

Import-Module ActiveDirectory

$groupName = "YourGroupName"

$memberlist = Import-Csv "C:\memberlist.csv"

foreach ($member in $memberlist) {

$emailusers = Get-ADUser -Filter { (mail -eq $member.email) } -SearchBase "DC=domain,DC=com" -SearchScope SubTree

if ($emailusers -ne $null)

{ Add-ADGroupMember -Identity $groupName -Member $($emailusers.SamAccountName)

    }

}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
This video discusses moving either the default database or any database to a new volume.

734 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