Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitNeed a quick way to fetch the members of a Microsoft 365 group and email them to an administrator? This Graph PowerShell script does exactly that — it retrieves the members of a specified group, constructs an HTML table, and sends the member list directly to the admin’s inbox.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Group.Read.All", "User.Read.All", "Mail.Send"
# Define the group and admin
$groupId = "7ac400b1-72fe-47a4-b437-57671ca08f86" # Replace with your group's ID
$adminEmail = "samadmin@7xh7fj.onmicrosoft.com" # Replace with the admin's email
# Get group details
$group = Get-MgGroup -GroupId $groupId
$groupName = $group.DisplayName
# Get group members
$members = Get-MgGroupMember -GroupId $groupId -All
# Build HTML table
$htmlTable = "<html><body>"
$htmlTable += "<h3>Group Name: $groupName</h3>"
$htmlTable += "<table border='1' cellpadding='5' cellspacing='0'>
"
$htmlTable += "
<tr><th>Name</th><th>Email</th></tr>"
foreach ($member in $members) {
$name = $member.AdditionalProperties.displayName
$email = $member.AdditionalProperties.mail
$htmlTable += "
<tr><td>$name</td><td>$email</td></tr>"
}
$htmlTable += "
</table>
</body></html>"
# Create email body
$emailBody = @{
Message = @{
Subject = "Member List for Group: $groupName"
Body = @{
ContentType = "HTML"
Content = $htmlTable
}
ToRecipients = @(
@{
EmailAddress = @{
Address = $adminEmail
}
}
)
}
SaveToSentItems = $true
}
# Send the email
Send-MgUserMail -UserId $adminEmail -BodyParameter $emailBody
The script starts by connecting to Microsoft Graph with the scopes:
The group is retrieved using its unique Group ID, and the display name is extracted. All members are pulled using Get-MgGroupMember -All.
The script creates a clean, formatted HTML table showing member display names and emails using AdditionalProperties.
The constructed table is embedded directly into the email body. The message is sent from the admin's account to their own inbox using Send-MgUserMail.
This script is clean and simple, but here are a few upgrades you could make:
In addition to HTML email, export a CSV copy of the members:
$members | ForEach-Object {
[PSCustomObject]@{
Name = $_.AdditionalProperties.displayName
Email = $_.AdditionalProperties.mail
}
} | Export-Csv -Path "GroupMembers.csv" -NoTypeInformation
Fetch group owners separately using Get-MgGroupOwner and merge both sets into one report.
Wrap this logic in a loop to send reports for all groups to the admin.
Run this script weekly or monthly for automated group audits.
Error | Cause | Solution |
---|---|---|
Unauthorized or Access Denied | Missing Graph permissions | Use Connect-MgGraph with the required scopes |
AdditionalProperties is null | Some members are not users | Add a type check or skip non-user objects |
MailboxNotEnabled | Admin account doesn't have a mailbox | Ensure samadmin@... has an Exchange Online mailbox |
Send-MgUserMail fails silently | UserId and From address mismatch | Ensure -UserId in Send-MgUserMail matches a valid mailbox |
This Graph PowerShell script is a handy solution for quickly retrieving and sharing Microsoft 365 group membership details. With an intuitive HTML report and direct delivery to the administrator’s inbox, it’s ideal for audits, team reviews, or periodic group monitoring.
✉️ With just a Group ID and an admin email, you can automate group visibility with zero fuss.
© m365corner.com. All Rights Reserved. Design by HTML Codex