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

Agile Methodology in Project Management

0 185 0

In this video, you will gain an understanding of Agile and Scrum Master Certification terminologies and concepts to help you make better decisions in your Project Management capabilities. Whether you’re a developer looking to obtain an Agile or Scrum Master Certification, or you’re a Project Manager/Product Owner who is attempting to get your product or … Continue reading Agile Methodology in Project Management

An Overview of Office 365 – Administration Portal and Admin Center

0 960 3

This is part 1 of our 5-part Office 365 free training course. In this Office 365 training video, instructor Spike Xavier introduces some of the most popular services found in Microsoft Office 365 including the Admin Portal and Admin Center. For instructor-led Office 365 training classes, see our course schedule: Spike Xavier SharePoint Instructor – … Continue reading An Overview of Office 365 – Administration Portal and Admin Center

Creating Users and Managing Passwords in Microsoft Office 365

0 809 5

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    

Write a Comment

Share your thoughts...

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