Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitDistribution Groups (also known as Distribution Lists) play a key role in traditional email-based communication across Microsoft 365 tenants. Unlike security groups or unified groups, distribution groups are strictly email-centric and are not used for permissions or collaborative workspaces.
This article demonstrates how to identify and fetch only Distribution Groups using Microsoft Graph PowerShell. We’ll walk through the script, explain how it works, suggest improvements, highlight possible errors, and wrap it up with a practical conclusion.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All"
# Retrieve only distribution lists (mail-enabled, NOT security or unified groups)
$distributionLists = Get-MgGroup -All | Where-Object {
$_.MailEnabled -eq $true -and
$_.SecurityEnabled -eq $false -and
($_.GroupTypes -eq $null -or $_.GroupTypes.Count -eq 0)
}
# Output results
$distributionLists | Select DisplayName, Mail, Id
Let’s break down the components of the script:
Here are a few ideas to build on top of the base script:
$distributionLists | Select DisplayName, Mail, Id | Export-Csv "DistributionGroups.csv" -NoTypeInformation
Include other useful properties such as CreatedDateTime, Description, or Visibility for a more detailed report.
Want to isolate certain departments? Add filters like:
$distributionLists | Where-Object { $_.DisplayName -like "HR*" }
Schedule the script using Task Scheduler or Azure Automation to run periodic reports on Distribution Groups.
Error Message | Cause | Solution |
---|---|---|
Access Denied or Insufficient privileges | Missing Group.Read.All delegated or application permissions. | Ensure you connect with Connect-MgGraph -Scopes "Group.Read.All" and that admin consent is granted. |
Get-MgGroup returns limited results | By default, Get-MgGroup is paginated. | Use the -All parameter to retrieve all groups across all pages. |
GroupTypes is not recognized | Null or empty values can throw exceptions if not handled properly. | Use condition: ($null -eq $_.GroupTypes -or $_.GroupTypes.Count -eq 0) to avoid runtime issues. |
Using Microsoft Graph PowerShell to fetch distribution groups offers precise control and visibility into how your organization manages group-based email communication. This script provides a reliable way to isolate classic distribution lists from the broader set of groups in your Microsoft 365 environment.
Whether you want to audit group types, generate compliance reports, or clean up unused distribution lists, this script gives you a strong foundation to build upon.
💡 For optimal results, integrate this script into regular administrative audits to keep your group directory organized and up to date.
© m365corner.com. All Rights Reserved. Design by HTML Codex