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.

001-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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.

002-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

003-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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.

004-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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.

005-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

006-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

007-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

008-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

So let’s fix this and do that again.

009-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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.

010-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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.

011-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

012-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

013-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

014-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

015-Using-PowerShell-to-Report-Distribution-Groups-in-Exchange-Server

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

Agile Methodology in Project Management

0 154 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 642 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    

Detailed Forensic Investigation of Malware Infections – April 21, 2015

4 608 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

See what people are saying...

  1. Avatar Laurent

    Works like a charm

  2. Avatar Narayan Pawar

    How to download the script you shown above?

  3. Avatar Cory

    This worked for me and did wonders. Now to see if it can handle a more complicated file creation.

  4. Avatar RB

    I had to use Get-DistributionGroupMember $i.Name. Just $i did not work for me.

  5. Avatar Tyson

    I stand corrected. This works great.

  6. Avatar tyson

    This DID NOT work for me at all.

  7. Avatar Tammy Rule

    Does this work for the SG- groups associated with the shared mailboxes? I have not found a way yet to list all shared mailboxes with the members. In our environment the SG- is a distrib tied to a shared mailbox. The naming convention is such that if I listed the name of the SG- it would be fairly easy to associate the shared mailbox with it. Thank you!

Share your thoughts...

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