July 10, 2011

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

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.

Exchange 2007 Articles, Exchange 2010 Articles, Powershell 8 Replies to “Quick Tip–Creating Distribution Groups from a CSV file using Powershell for a LAB environment….”
Andy Grogan
Andy Grogan


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

    Author’s gravatar

    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…

    Author’s gravatar

    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.

    Author’s gravatar

    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.

    Author’s gravatar

    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.

    Author’s gravatar

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

    Author’s gravatar

    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

    Author’s gravatar

    Thanks for the script, it is exactly what I am looking for but my issue, everytime I run it, it keeps asking to manually put the samaccountname even though I have filled it out in the CSV file. I receive “cmdlet New-DistributionGroup at command pipeline position 1
    Supply values for the following parameters:

    I know this is an old thread but I am trying my luck here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Do NOT follow this link or you will be banned from the site!
%d bloggers like this: