?
Solved

Creating Distribution Groups in PS

Posted on 2016-11-22
2
Medium Priority
?
86 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
2 Comments
 
LVL 20

Assisted Solution

by:Peter Hutchison
Peter Hutchison earned 1000 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 38

Accepted Solution

by:
Mahesh earned 1000 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Steps to fix “Unable to mount database. (hr=0x80004005, ec=1108)”.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
how to add IIS SMTP to handle application/Scanner relays into office 365.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

864 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