Create a bunch of Standard Distribution Groups from a CSV file

Some customers make extensive use of standard distribution groups in Outlook Live to organize and communicate with users.  Just like it is possible to create and manage mailboxes with CSV files… the same is true of groups, and you can write a script to do this.  You should use CSV Parser as a guide here.

Assuming a csv file that looks like this…

Name,Alias,DisplayName,Type
Chess,Chess,Chess Club,Security
Computer,Computer,Computer Club,Security

…the key elements you will need to build into the script are as follows:

Read the fields pertaining to the groups you want to create into an array ($Records).  I use import-csv for this:

$records = import-csv -Path c:\groups.csv -OutVariable string

Build a For…Each Loop to process each row in the array and run it through the New-DistributionGroup cmdlet.  PowerShell is a fairly  flexible environment to work with, and you can create and work with array rows on the fly (e.g. $Group)

foreach ($group in $records)
{
    $this_name                 = $group.name
    $this_alias                   = $group.alias
    $this_displayname       = $group.displayname
    $this_type                   = $group.type

# create distribution group – assigning result to variable to avoid listing the new object
%{Invoke-Command -Session $Session1 {param ($this_name,$this_alias,$this_displayname,$this_type) New-DistributionGroup -Name $this_name -Alias $this_alias -DisplayName $this_displayname -Type $this_type}-arg $this_name,$this_alias,$this_displayname,$this_type} > $results

}

I hope this helps!

Jonny

Advertisements

One Response to Create a bunch of Standard Distribution Groups from a CSV file

  1. bob says:

    Awesome.

    One thing though – you specify the session as $Session1. Most noobs (like myself) will have followed this article (http://207.46.16.237/en-us/140/cc952755.aspx) to connect Powershell to Outlook live and therefore their session variable is called $Session.

    This is why it failed the first time for me.

    I’m a Powershell newbie (though fast learning for live@edu!) so it took me a while to spot.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: