Solved

Creating Distribution Groups in PS

Posted on 2016-11-22
2
22 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 18

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 35

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now