Archived Note: Combined function in Public Distribution Group and Mailbox Forward Report
Public distribution lists are open to external senders who pose a risk to the organization. External threats such as phishing, whaling, compromised business partners (business email compromise attacks), and other social engineering tactics are concerns. Therefore, a proactive approach to risk management is crucial, even if the groups are limited to specific external senders.
To address these challenges, this script is designed to automate the generation of a report of members for Distribution Lists open to external senders in Microsoft 365’s Exchange Online or on-premises Exchange servers.
For further reporting capabilities, refer to the Mailbox Forward Report feature, which enables the retrieval of reports encompassing all user and shared mailboxes with forwarding SMTP addresses configured.
- Download or make copy of script here
- Take note of the script’s path
- Open PowerShell as an administrator
- Use
Set-ExecutionPolicy -ExecutionPolicy <VALUE> -Scope <VALUE>to change to acceptable Execution Policy - Optional: Navigate to directory location of script using
cdcommand (Example:cd “C:\MyFolder”) - Run PowerShell Script
.\<scriptname>.ps1orC:\MyFolder\<scriptname>.ps1
-OutputPathAllows the user to specify the location of the exported CSV file.
-DomainsSpecifies the email domains to be used for filtering external members. This parameter accepts a comma-separated list of domains. If not provided, the script will end.
-onpremEXSkips the connection to Exchange Online sessions entirely for Exchange Management Shell. Use this switch if you want to use for Exchange On-Premise.
publicDLreport -Domains "domain1.com,domain2.com" -OutputPath "C:\Reports"publicDLreport -Domains "domain1.com,domain2.com"Run the function to generate a report for public distribution lists for Exchange On-Premise examples
publicDLreport -Domains "domain1.com,domain2.com" -OutputPath "C:\Reports" -onpremEX publicDLreport -Domains "domain1.com,domain2.com" -onpremEXImportant Note: CSV report will show as PublicDLreport_yyyyMMdd_HHmmss.csv in current directory of terminal if -OutputPath not specified.
Important Note: PrimarySMTPAddress will show empty for internal members still apart of group with no mailbox. This will show an error in terminal and will be excluded from CSV report.
-- Exchange Online PowerShell V2 module, version 2.0.4 or later
-- Powershell 7 or later
-- Exchange Server 2013, 2016, and 2019
Install Exchange Online Powershell module
Install-Module ExchangeOnlineManagement -ForcePlease Note: This will require restart of terminal after install. Only use for first time accessing Exchange Online via Powershell on local machine.
-- The -onpremEX switch is required when running function in Exchange Management Shell
-- Always test the script in a non-production environment first.
-- Review the script's code and understand its functionality before execution.
-- The script may require specific permissions or elevated privileges to run correctly.
-- The script's behavior may vary depending on the system configuration and environment.
Open to all collaboration 🙏🏽
Please follow best practice outlined below:
- Fork from the
mainbranch only - Once forked, make branch from
mainwith relevant topic - Make commits to improve project on branch with detailed notes
- Test, test, test and verify
- Push branch to
mainin your Github project - Test, test, test and verify
- Open pull request to
mainwith details of changes (screenshots if applicable)
Once steps complete, I will engage to discuss changes if required and evaluate readiness for merge. Cases where pull requests are closed, I will provide detailed notes on the why and provide direction for your next pull request.
How to support? Buy me coffee ☕️ via Paypal

