Solved

Creating Distribution Groups in PS

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
This video discusses moving either the default database or any database to a new volume.

717 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