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 0Mike 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.”

001-Bulk-Membership-in-PowerShell-distribution-groups

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

002-Bulk-Membership-in-PowerShell-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.”

003-Bulk-Membership-in-PowerShell-finance

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

004-Bulk-Membership-in-PowerShell-finance

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.

005-Bulk-Membership-in-PowerShell-pipeline

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

006-Bulk-Membership-in-PowerShell-pipeline

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

You may also like:  Using PowerShell to convert to the MiniShell on a Server 2012 R2 Datacenter Core Edition

007-Bulk-Membership-in-PowerShell-pipeline

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

008-Bulk-Membership-in-PowerShell-pipeline

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).

009-Bulk-Membership-in-PowerShell-get-mailbox-filter

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.

010-Bulk-Membership-in-PowerShell-get-mailbox-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.

011-Bulk-Membership-in-PowerShell-new-distribution

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.

You may also like:  How to Remotely Enable and Disable (RDP) Remote Desktop

012-Bulk-Membership-in-PowerShell-new-distribution

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.”

013-Bulk-Membership-in-PowerShell-new-distribution

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

014-Bulk-Membership-in-PowerShell-new-distribution

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.”

015-Bulk-Membership-in-PowerShell-new-distribution

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.”

016-Bulk-Membership-in-PowerShell-new-distribution

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.

017-Bulk-Membership-in-PowerShell-new-distribution

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 21 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

Creating Users and Managing Passwords in Microsoft Office 365

0 30 1

In this Office 365 training video, instructor Spike Xavier demonstrates how to create users and manage passwords in Office 365.

Detailed Forensic Investigation of Malware Infections – April 21, 2015

1 79 1

In this IT Security training video, Security expert Mike Danseglio (CISSP / CEH) will perform several malware investigations including rootkits, botnets, viruses, and browser toolbars.

Write a Comment

Share your thoughts...

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