• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Use PowerShell to get a list of Distribution Group members

Slipstick Systems

› Exchange Server › PowerShell › Use PowerShell to get a list of Distribution Group members

Last reviewed on September 5, 2024     1 Comment

Applies to: Office 365 Exchange

A user wanted to know how to export a list of distribution group members. He specifically wanted the alias and primary smtp address.

Exchange online admins can export the members in Azure Active Directory portal.
Log into The Azure portal and under All Services, select Groups.

Select the distribution group you want to export. Under Bulk Operations, select Download members. The values shown on the screen are downloaded.
export distribution group

The drawback: you need to export one distribution group at a time and the fields you see are what you get. Basically, name and email address only.

The methods on this page require Exchange admin access. If you need to export the distribution group from Outlook, see Use VBA to Create a List of Exchange GAL Members for a VBA version.

PowerShell will allow you to export one or more lists and get any field available in the GAL entry.

exported dl list

This PowerShell creates a CSV file for every DL in the organization, containing each member's name, email address, and alias.

If you need more fields, add them to this line in the code. (A list of available field names is below.)

Get-DistributionGroupMember -Identity $DL | Select-Object DisplayName, PrimarySmtpAddress, ExternalEmailAddress, Alias | Export-Csv -Path $exportfile

$DGs = Get-DistributionGroup 
 # export every DL
 foreach ($DLList in $DGs)
    {  
 $DL = $DLList.DisplayName 
     
 # get distro list 
 Get-DistributionGroup -Identity $DL

 # Save as csv in the user's documents directory 
 $exportfile = $HOME + '\Documents\' + $DL + '_Members.csv' 

 # get the members & select columns, export to a csv file 
 Get-DistributionGroupMember -Identity $DL | Select-Object DisplayName, PrimarySmtpAddress, ExternalEmailAddress, Alias | Export-Csv -Path $exportfile  

    }  

powershell ise

 
If you only need the members of one distribution group, this PowerShell exports each member's name, email address, and alias in a specific distribution group to a CSV file. You can add the group name in the code or type it in when you run the PowerShell.

clear
$NF =""

# Add the DL name to the code or enter it when you run the script
# DL names are not case sensitive
#$DL = "testgroup"  
$DL = Read-Host "Enter the DL name"

write-host $DL
# check to see if list exists
try{Get-DistributionGroup -Identity $DL} catch{$NF="Distribution List Not Found"} 
 
# if the name of the distribution group was entered correctly then $NF will still be null 
if($NF -eq "")  
 {
 # Save the distribution member details as csv in the user's documents directory 
 $exportfile = $HOME + '\Documents\' + $DL + '_Members.csv' 

 # get the members but only select certain columns - export the results to a csv file 
 Get-DistributionGroupMember -Identity $DL | Select-Object DisplayName, PrimarySmtpAddress, ExternalEmailAddress, Alias | Export-Csv -Path $exportfile  
}

Else 
{
Write-host "Check your spelling, the DL was not found"
}

 
This table lists the fields that would contain data you might want to include in the export. See ExchangeUser members for the complete list.

Field nameDescription
AddressThe X400 e-mail address of the Exchange User
AddressEntryUserTypeReturns olExchangeUserAddressEntry which represents the user type of
the ExchangeUser
AliasThe user's alias
AssistantNameName of the user's assistant
BusinessTelephoneNumberBusiness telephone number
CityCity
CommentsComments in the GAL entry
CompanyNameThe name in the Company field
DepartmentThe department field
DisplayTypeReturns olUser from the OlDisplayType representing the nature of the
ExchangeUser
FirstNameThe user's first name
JobTitleThe job title of the user
LastNameThe last name of the ExchangeUser
MobileTelephoneNumberThe mobile telephone number
NameReturns the display name for the ExchangeUser object
OfficeLocationThe office location field
PostalCodePostal code
PrimarySmtpAddressThe primary Simple Mail Transfer Protocol (SMTP) address
StateOrProvinceState or province
StreetAddressStreet address

 

Using PowerShell Scripts

To use PowerShell scripts with Exchange online, start typing powershell on the start menu and open Windows PowerShell when it comes up. You need to choose Run as Administrator. (Windows PowerShell ISE has a scriipt pane at the top, which is useful if you want to edit the script. )

You'll need to load the ExchangeOnlineManagement using before using the script. Type or paste these two lines in the PwerShell (in Administrator mode).

Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName [email adddress or alias] 

Paste the entire script in the PowerShell window and press Enter or the Run button if using PowerShell ISE.

Saving PowerShell Scripts

If you want to save the script as a .ps1 file, paste it into Notepad and save it with the extension .ps1. To open it in the PowerShell IDE, type powershell on the start menu and click on Windows PowerShell IDE when the PowerShell app is found. Paste the script in the editing window.

To use it, you need to allow local scripts by running this command:

Set-ExecutionPolicy RemoteSigned

To run your saved .ps1 file, right-click on the script and choose Run with PowerShell.

More Information

ExchangeUser object (Outlook) | Microsoft Docs

Use PowerShell to get a list of Distribution Group members was last modified: September 5th, 2024 by Diane Poremsky

Related Posts:

  • Use Powershell to configure Automatic Replies
  • How to Print an Exchange Distribution List
  • Use VBA to Create a List of Exchange GAL Members
  • How to convert contact groups to individual contacts using Import or a
    Create Individual Contacts from a Distribution List

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
1 Comment
newest
oldest most voted
Inline Feedbacks
View all comments

Anders L
November 22, 2022 4:55 am

How can i define, so it only takes a specific OU and not all the Distribution groups?

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 30 Issue 29

Subscribe to Exchange Messaging Outlook






Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Jetpack plugin with Stats module needs to be enabled.
  • Move Deleted Items to Another Folder Automatically
  • Open Outlook Templates using PowerShell
  • Count and List Folders in Classic Outlook
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
Ajax spinner

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in classic Outlook (Windows).

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




New Outlook Articles

Move Deleted Items to Another Folder Automatically

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Newest Code Samples

Open Outlook Templates using PowerShell

Count and List Folders in Classic Outlook

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

:wpds_smile::wpds_grin::wpds_wink::wpds_mrgreen::wpds_neutral::wpds_twisted::wpds_arrow::wpds_shock::wpds_unamused::wpds_cool::wpds_evil::wpds_oops::wpds_razz::wpds_roll::wpds_cry::wpds_eek::wpds_lol::wpds_mad::wpds_sad::wpds_exclamation::wpds_question::wpds_idea::wpds_hmm::wpds_beg::wpds_whew::wpds_chuckle::wpds_silly::wpds_envy::wpds_shutmouth:
wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment