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

by Andy Grogan on July 10, 2011 · 9 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;


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:


– see below


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


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


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


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


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


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

{ 8 comments… read them below or add one }

Leave a Comment


{ 1 trackback }

Previous post:

Next post: