Quick Tip–Creating Distribution Groups from a CSV file using Powershell for a LAB environment….

by Andy Grogan on July 10, 2011 · 8 comments

in Exchange 2007 Scripts, Exchange 2010 Scripts, Powershell, Quick Tips, Test Labs

In a previous article, I provided a Powershell script which could be used to create a number of users for use within a Lab (test environment). Moving on from that, I recently started thinking about other elements of Exchange that are typically very repetitive to perform, but are also needed within an LAB infrastructure – one such example is Distribution Groups.

Script & Sample Distribution Group CSV Download

[ Create Distribution Groups from CSV – Powershell – 2KB ]

[ Sample Distribution Group CSV File – 2KB ]

Using the script

Download both the Powershell script and the Sample CSV file to your Exchange LAB server.
You have the option of editing the CSV file before you use it – there are 33 pre-defined sample distribution groups – however you can add more should you wish.

The CSV file is structured into two columns – like so;

distGroupsCreate006

You can include spaces in the “Name” Column to form the Display Name for the Distribution List, however it is recommended that you do not include spaces in the “samAccountName” column (as this forms both the samAccountName and the Alias for the Distribution list).

Furthermore within the script you will need to modify the destination OU location within AD where the script places each of the distribution lists.
In order to do this, before you execute the script – open the Powershell script file and locate the following Variable:

$OU = "OU=DistLists,OU=ExchangeUsers"

You will need to change this to reflect an OU structure within your LAB’s Directory (if you have used the Create Users script [above] then the basic OU structure will already be present)

In order to execute the script, open an Exchange Management Shell and navigate to the location where you have downloaded the script file to.

Enter in the following command line at the Powershell Prompt:

.\CreateDistList-OUVersion.ps1

– see below

distGroupsCreate001

You will be prompted to navigate to the location of the sample CSV file – located it and click on the “OK” button – see below

distGroupsCreate002

The script will firstly create the OU structure – and pause for 1.5 minutes – this is to allow for the new OU to be replicated to all domain controllers in the LAB environment before the Distribution Groups are created  – if your environment only has a single domain controller you can remove the following line from the script:

CountDown 1.5

Incidentally the “countdown” function used within the script is borrowed from here: http://poshtips.com/2010/03/29/powershell-countdown-timer/ By xb90

distGroupsCreate005

When the Countdown has completed – the script will then create the Distribution Groups – see below.

distGroupsCreate003

When the script has completed you can check to ensure that the groups have been created properly by opening Active Directory Users and Computers and navigating to where you would expect the OU within the script to be created – see below

distGroupsCreate004

When you click on the OU you should see all of the Distribution Lists from the file listed in the details pane – see below

distGroupsCreate007

That concludes this Quick Tip – I hope that someone finds this useful.

{ 8 comments… read them below or add one }

James July 25, 2011 at 10:27 pm

Thanks for the script…It would be great if I could get this to function properly on my work’s AD server, but I have encountered several errors in testing. First I’d like to know what the server environment requirements are for running this script (ie: Powershell 1 vs. 2, Server OS, etc). I’m trying to get this to work on a Server 2008 Enterprise Active Directory server using Powershell version 1, but i keep getting the same 3 basic error’s 1) exception calling “SetInfo” with “0″ argument(s):… 2) the term ‘Get-OrganizationalUnit’ is not recognized as a cmdlet… 3) the term ‘New-DistributionGroup’ is not recognized as a cmdlet…

Reply

Andy Grogan July 26, 2011 at 7:23 am

Sorry James, for some reason I had thought that I put the requirements in the article – obvisouly not from reviewing it.
Ok, in order to use the script it should be downloaded and executed on an Exchange Server which has Powershell v.2.
Powershell 2 for the Get-Organizational unit and the Exchange Management shell for the New-Distribution group.
Cheers
A

Reply

ugresen bhal August 4, 2011 at 5:41 pm

Dear sir, it’s great. really it’s easy ot make 1000 mailbox at a time. thank you so mcuh. please give any tips, how to make easy life in Exchange. thank you once again.

Reply

Mahesh August 24, 2011 at 10:29 pm

Sir. Thanks a lot. This is really helpfull. Would appreciate if you could help me to create a script based on following requirments:

1: Create DLs using CSV file.
2: Should have option to specity doamin and OU, defining admin/owner’s name in Notes field, add members to DL, assign rights to owners to modify the membership.

Basically we are planning to delegate this task to our service desk staff.
Regards

Reply

hameed March 13, 2014 at 1:11 pm

hi guys,
any idea to include owener / co-owner details in CSV ? so that it will reflect in AD?
thanks

Reply

Mark August 27, 2014 at 7:06 am

Works well Thanks for the script, modified it slightly to exclude the creation of OU, since it was already created

Also in regards to adding owner info you just need to include the -ManagedBy parameter, I’m surprised to see that you actually cant add Description info, doesn’t appear to be a Description parameter

Reply

meet date September 17, 2014 at 6:17 am

I’m amazed, I must say. Rarely do I encounter a blog that’s equally educative and entertaining,
and let me tell you, you’ve hit the nail on the head.
The problem is something that too few people are speaking intelligently about.
I am very happy that I found this during my search for
something relating to this.

Reply

relationships improve September 21, 2014 at 12:19 pm

It’s actually a great and helpful piece of information. I’m happy that you simply shared this useful information with us.
Please stay us up to date like this. Thanks for sharing.

Reply

Leave a Comment

*

Previous post:

Next post: