[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Create Bulk Distribution Groups with Various Members using Powershell 2.0

Posted on 2014-03-07
7
Medium Priority
?
542 Views
Last Modified: 2014-03-12
I have a need to create 10 Distribution Groups with various members in them. Please assist in providing the PS script.

CSV Columns may be:

Usernames, DG names, Alias
0
Comment
Question by:Anthony K O365
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39913636
$ou = "your ou in OU=xxx,dc=xxx,dc=xx,dc=x"
$Contents = import-csv = "path"
foreach ($content in $contents)
{
New-DistributionGroup -Name $content.dgnames -OrganizationalUnit $OU -SamAccountName $content.username -Type "Security"
}

put you csv file in column and rename "DG Names" to "DGnames" no space
0
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39913638
$Info = Import-CSV C:\pathToFile\DGs.csv

$info | % {

  New-DistributionGroup -Name $_.DGName

}

$info | % {

  Add-DistributionGroupMember -Identity $_.DGName -Member $_.username

}

Open in new window

0
 
LVL 14

Expert Comment

by:Justin Yeung
ID: 39913642
is the username in all DG group?
0
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 

Author Comment

by:Anthony K O365
ID: 39920351
Here is what I have:

UserName, DGName1, DGName2, DGname3
user1  
user2
user3
user4

User1 is part of DGName1 and DGName3
User2 is part of DGName2 and DGName3
User3 is part of DGName1 and DGName2

so I have 100 users and they are part of 10 different DG's. How would I structure the csv file?
0
 
LVL 4

Accepted Solution

by:
Jason Ryberg earned 2000 total points
ID: 39920486
Are you manually creating the CSVs?  I only ask because scripts are usually based on information that already exists.  So that said, the structure of the CSV would depend on which set of data would require less typing.  Without seeing a representative dataset, it's hard to recommend which way to go.  Assuming each user is in a DG, I would create the CSV like this (see attached file for actual test data):

UserName Membership
user1          DG1,DG2,DG10
user2          DG2,DG3,DG7
user3          DG8,DG1,DG2

It would be preferable to have created the DGs beforehand (thus eliminating the need to check for DG creation within the loop):

$DGs = Import-CSV C:\pathToCSV\DGs.csv

$DGs | % {

  New-DistributionGroup -Name $_.DGName

}

Open in new window


I would then nest a loop for the entire file to add membership to each user:

$users = Import-CSV C:\pathToFile\Users.csv

$users | % {

  $username = $_.Username
  $membership = $_.Membership.split(",")

  $membership | % {

    Add-DistributionGroupMember -Identity $_ -Member $Username

  }

}

Open in new window

test.csv
0
 

Author Comment

by:Anthony K O365
ID: 39920819
Yes, the DG's are already created.
0
 

Author Closing Comment

by:Anthony K O365
ID: 39923299
This took care of my needs.

Thank you!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Are you an Exchange administrator employed with an organization? And, have you encountered a corrupt Exchange database due to which you are not able to open its EDB file. This article will explain all the steps to repair corrupt Exchange database.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
To show how to create a transport rule 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 Mail Flow >> Rules tab.:  To cr…

649 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