Using PowerShell to report on Distribution Group Membership in Exchange Server

Home > Blogs > Exchange Server > Using PowerShell to report on Distribution Group Membership in Exchange Server

Using PowerShell to report on Distribution Group Membership in Exchange Server

1 7 Mike Pfeiffer
Added by January 13, 2013

Using PowerShell to Report on Distribution Group Membership in Exchange Server
Instructor: Mike Pfeiffer.

First, I’m going to take a look at my distribution groups that I currently have by running Get-DistributionGroup.


You could see that I’ve got two groups Sales and Marketing. If I want to look at the members of those groups I can type Get-DistributionGroupMember sales and it gives me that list.


Or I could say give me everybody that is in marketing Get-DistributionGroupMember marketing and there’s that list.


What I might want to export this to an actual report csv or html or something like that. You might think that you could do something like Get-DistributionGroup. So I’ll use get all the groups, pipe that over to Get-DistributionGroupMember.

Get-DistributionGroup | Get-DistributionGroupMember

It seems like that would work but what you get back here after hitting enter is a list of users.


We have no real idea of what group they came from. So even though this produces a clean one‑liner, you really have no clear references to where that group was to where they came from.

So what you got to do is loop through this and keep track of what group they’re in before you can export this as a report. This is going to require some scripting, there’s a couple of ways that you could tackle this particular issue.

One thing I’m going to use is the foreach loop to handle this. So what I’m going to do is instead of using the pipeline I’m going to do a foreach. This is a looping construct in PowerShell. Let’s use a temporary variable to reference each group. I’m going to say foreach ($i) and all my distribution groups, I want to run the get distribution group cmdlet.


I want to do a select name and create a calculated or custom property specifying the group name.


So I will get the name of the user and then I would create my custom property so I could type name = or I could just do (n) for an abbreviation and say member and my expression. I could abbreviate that as well so just a simple e={$i.Name}.


I’ll run this and then I notice that I’m missing a keyword here for each variable (in) your command.


So let’s fix this and do that again.


We get a list of the members and we get a list of the group that they’re in and that’s easy to keep track of.


I could export this out to csv, but instead of doing an export from here, I would actually have to save this information because I’m using this loop. I’m not using the pipeline so I’ll say $groupmembers. Then once that report has been generated or that data has been gathered, I can pipe that out to a csv file with $groupmembers | Export-csv without any type information.


I run the report and after that complete second go ahead and open that file up in Excel.


The nice thing here with this is you can take advantage of Excel’s filtering capabilities.


Now I can say let me just see everybody that’s inside Sales.


That customizes that list for me or I can filter on the other one.


So if I have a large number of groups and a lot of group members, this is an easy way for me to dump this data into Excel and easily filter on it and get a bird’s eye view real quick of the information that’s out there.


Videos You May Like

A Simple Introduction to Cisco CML2

0 3876 0

Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2

Cable Testers and How to Use them in Network Environments

0 720 1

This content is from our CompTIA Network + Video Certification Training Course. Start training today! In this video, CompTIA Network + instructor Rick Trader demonstrates how to use cable testers in network environments. Let’s look at some tools that we can use to test our different cables in our environment. Cable Testers Properly Wired Connectivity … Continue reading Cable Testers and How to Use them in Network Environments

Government Edition – Encrypting a USB Flash Drive in Windows 10

0 274 2

In this video, Security Instructor Mike Danseglio demonstrates how to use BitLocker in Window 10 to secure files on a USB Flash drive that adhere to stricter data protection requirements as found inside Government entities. BitLocker 2-day instructor-led training is now available at Interface: BITLOCK: Planning and Deploying BitLocker Drive Encryption Training Video Transcription: Hi. … Continue reading Government Edition – Encrypting a USB Flash Drive in Windows 10

Write a Comment

See what people are saying...

    Share your thoughts...

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