Populate a Standard Distribution Group with members using a CSV file

Related to my previous post on creating groups from a csv file, I thought I would take this one stage further and also think about how you can populate the group with members.

In this case, I am keeping the csv file simple… a simple pairing of a group alias with a user alias:


…just like the last post…the key elements you will need to build into the script are as follows:

Read the pairs pertaining to the groups and members you want to create into an array ($Memsfile).  I use import-csv for this:

$Memsfile = import-csv -Path c:\mems.csv -OutVariable string

Build a ForEach Loop to process each row in the array and run it through the Add-DistributionGroupMember cmdlet. 

foreach ($Mem in $MemsFile)
    $this_name                       = $Mem.Name
    $this_DistributionGroup     = $Mem.DistributionGroup

# add mailbox to distribution group – assigning result to variable to avoid listing the new object
%{Invoke-Command -Session $Session1 {param ($this_name,$this_DistributionGroup) Add-DistributionGroupMember -Identity $this_DistributionGroup -Member $this_Name}-arg $this_name,$this_DistributionGroup} > $results


I hope this helps! Of course you can also use the same techniques and even csv file to remove distribution group members… just change Add-DistributionGroupMember to Remove-DistributionGroupMember.



2 Responses to Populate a Standard Distribution Group with members using a CSV file

  1. Mike says:

    A short video on this would be helpful…

  2. US LiveAtedu says:

    Unfortunately I cannot give away fully working scripts (even though I have several now). What happens is that folks download them, and then expect our support teams to be able to fix them if there are issues… not pretty :(The best I can tell you here is that you can take the CSV Parser script that we do provide, strip it down to the bare essentials around reading in parameters and importing csv files, and then swap in some of the statements I have provided here.Of course if someone wants to top and tail what I have done … please do so, and then submit it to http://www.microsoft.com/technet/scriptcenter/csc/default.mspx. I see that they are currently crying out for PowerShell script samples… Drop me a note if you choose to do this, and I will ensure you get some kudos!

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: