Managing Memberships in Bulk in PowerShell

Home > Blogs > Exchange Server > Managing Memberships in Bulk in PowerShell

Managing Memberships in Bulk in PowerShell

Like This Blog 0 Mike Pfeiffer
Added by March 14, 2014

You might find that managing the membership of Distribution Groups in PowerShell is something you do more frequently than actually create the groups from scratch.

But we’ll look at both scenarios here. Let’s say that we need to create a group for finance users. So I’m going to do a new Distribution Group called “Finance.” I’m going to tab through these parameters here, and under type, what I’m going to say is “distribution.”


This is going to be a Distribution Group and Active Directory that’s mail‑enabled. That gets created. It gets created as universal.


What I want to do from there is add some users to that group. We have a bunch of different Cmdlets to manage Distribution Groups. What I’m going to do is run Get‑Mailbox and query the organizational unit, “Finance.”


I want to pull all these users that are all in this OU and dump them in that group.


This is how we can do some bulk administration of groups. So we’ve created our Finance group. From here, I want to take all of these users in the OU and put them in that group.

Luckily, we don’t have to do any loops for this. We don’t have to iterate over anything. We can simply make use of the pipeline because the Add Distribution Group Cmdlet gladly accepts input from anything sent over from Get‑Mailbox.


We can simply say add Distribution Group Member “Finance.”


Now, we don’t get anything back. That means that the command completed successfully.


To check that we could just do a Get‑DistributionGroup Member on Finance.


Now all of the users that we saw previously are actually there now.

There are other ways that you can filter on this information. We’re using one of the server-side parameters here to pull from an Organizational Unit (OU).


You could also do something like this where you’re piping to where object and maybe say well give me all the ones that the Office is equal to sales.


You might find that sometimes you got parameters on the actual get Cmdlet where you don’t have to do this late filtering. But that might be another way where you could continue piping down. Notice that Office isn’t a parameter here, so that’s something that you have to filter on. Just a couple of ideas to have the pipeline feed that add Get‑DistributionGroup Member Cmdlet.

Let’s look at one more example.

I’m going to do a new Distribution Group “Accounting,” and this time I’ll do it as a security group in Active Directory, that’s going to be mail‑enabled.


You can see that by looking at the group type information that comes back. So it’s a universal security group at this point. I can assign permissions on a NTFS share if I needed to on these group members. I’ll also send mail to this group.

Now that that group’s created I’m going to do something different this time. I’m going to run Get‑User and I’m going to say, “Recipient type details, user mailbox,” so it will only give me active directory users that have a mailbox.


I’m going to filter on a different property this time. I’m going to look for a title of accountant so $_.title ‑eq “Accountant.”


Let’s make sure that actually works first. Looks like that works just fine.


So these might be spread out multiple OU’s, running Get‑Mailbox and specifying the OU wouldn’t work in this case. I’m going to take that one liner and I’m going to continue piping over to add Distribution Group Member “Accounting.”


Take all those users and put them in that group.

No errors come back so we could just verify that by running GetDistributionGroupMember on “Accounting.”


And as you can see everything is there at that point.

One of the things to mention is that you can obviously modify these groups by running the Set‑DistributionGroup Cmdlet.


You can come in here and change sales and there are a number of parameters. You can enable moderation, do a number of things to modify these groups.

That’s how you provision and modify groups and also add multiple members into a group at one time.

Videos You May Like

Creating Users and Managing Passwords in Microsoft Office 365

0 661 3

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.   For instructor-led Office 365 training classes, see our course schedulle: Spike Xavier SharePoint Instructor – Interface Technical Training Phoenix, AZ 20347: Enabling and Managing Office 365    

JavaScript for C# Developers – September 24, 2014

0 487 3

Is JavaScript worth taking the time to learn if I’m a server-side .NET developer? How much of C# carries over to JavaScript? In this recorded video from Dan Wahlin’s webinar on September 24,2014, Dan answers these questions and more while also discussing similarities between the languages, key differences, and the future of JavaScript (ES6). If … Continue reading JavaScript for C# Developers – September 24, 2014

Detailed Forensic Investigation of Malware Infections – April 21, 2015

4 616 5

How does an investigator hunt down and identify unknown malware? In this recording of our IT Security training webinar on April 21, 2015, Security expert Mike Danseglio (CISSP / CEH) performed several malware investigations on infected computers and identify symptoms, find root cause, and follow the leads to determine what’s happening. He demonstrated his preferred … Continue reading Detailed Forensic Investigation of Malware Infections – April 21, 2015

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.