Book Image

Microsoft Exchange Server Powershell Cookbook (Update)

Book Image

Microsoft Exchange Server Powershell Cookbook (Update)

Overview of this book

Table of Contents (21 chapters)
Microsoft Exchange Server PowerShell Cookbook Third Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Reporting on distribution group membership


One of the common requests that you are likely to receive as an Exchange administrator is to generate a detailed report of which recipients are members of one or more distribution groups. In this recipe, we'll take a look at how to retrieve this information from the Exchange Management Shell.

How to do it...

To view a list of each distribution group member interactively, use the following code:

foreach($i in Get-DistributionGroup -ResultSize Unlimited) {
  Get-DistributionGroupMember $i -ResultSize Unlimited | 
  Select-Object @{n="Member";e={$_.Name}},
  RecipientType,
  @{n="Group";e={$i.Name}}
}

This will generate a list of Exchange recipients and their associated distribution group membership.

How it works...

This code loops through each item returned from the Get-DistributionGroup cmdlet. As we process each group, we run the Get-DistributionGroupMember cmdlet to determine the member list for each group, and then use Select-Object to construct a custom...