Over time, Microsoft 365 tenants accumulate unused groups created for short-term projects, accidental provisioning, or abandoned collaboration setups. Empty Microsoft 365 groups (Unified groups) clutter your directory, complicate governance, and may even lead to access confusion during audits.
This Graph PowerShell script helps administrators identify empty Microsoft 365 groups that are not Teams-enabled, generate a structured report, and email the results automatically for review and cleanup.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Connect-MgGraph -Scopes "Group.Read.All", "GroupMember.Read.All", "Mail.Send"
$AdminUPN = "admin@yourtenant.onmicrosoft.com"
$unifiedGroups = Get-MgGroup -All -Property Id, DisplayName, Mail, GroupTypes, CreatedDateTime, ResourceProvisioningOptions |
Where-Object {
$_.GroupTypes -contains "Unified" -and
($_.ResourceProvisioningOptions -notcontains "Team")
}
Write-Host "`nChecking each Microsoft 365 Group (excluding Teams) for members..." -ForegroundColor Cyan
$emptyUnifiedGroups = foreach ($group in $unifiedGroups) {
$members = Get-MgGroupMember -GroupId $group.Id -ErrorAction SilentlyContinue
if (-not $members) {
[PSCustomObject]@{
DisplayName = $group.DisplayName
Mail = $group.Mail
GroupId = $group.Id
CreatedDate = $group.CreatedDateTime
}
}
}
if ($emptyUnifiedGroups) {
Write-Host "`nEmpty Unified Groups found (excluding Teams):`n" -ForegroundColor Green
$emptyUnifiedGroups | Format-Table DisplayName, Mail, GroupId, CreatedDate
} else {
Write-Host "`nNo empty unified groups found." -ForegroundColor Yellow
}
$ReportPath = "$env:TEMP\Empty_M365_Groups_Report.csv"
$emptyUnifiedGroups | Export-Csv -Path $ReportPath -NoTypeInformation -Encoding UTF8
$groupCount = if ($emptyUnifiedGroups) { @($emptyUnifiedGroups).Count } else { 0 }
$Subject = "Empty Microsoft 365 Groups Report (Excluding Teams) — $(Get-Date -Format 'yyyy-MM-dd')"
$Body = @"
Hello Admin,<br><br>
Attached is the <b>Empty Microsoft 365 Groups Report</b> (Unified groups excluding Teams-enabled groups).<br>
Total empty groups found: <b>$groupCount</b><br><br>
Regards,<br>
Graph PowerShell Script
"@
$AttachmentContent = [System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes($ReportPath))
$Attachments = @(
@{
"@odata.type" = "#microsoft.graph.fileAttachment"
Name = [System.IO.Path]::GetFileName($ReportPath)
ContentBytes = $AttachmentContent
}
)
$Message = @{
Message = @{
Subject = $Subject
Body = @{
ContentType = "HTML"
Content = $Body
}
ToRecipients = @(
@{ EmailAddress = @{ Address = $AdminUPN } }
)
Attachments = $Attachments
}
SaveToSentItems = "true"
}
Send-MgUserMail -UserId $AdminUPN -BodyParameter $Message
Write-Host "Empty M365 groups report emailed successfully to $AdminUPN" -ForegroundColor Green
The script signs in using these delegated permissions:
It retrieves all groups and filters to include only:
This ensures the script targets only standalone M365 groups.
For each unified group, the script calls:
Get-MgGroupMember -GroupId <id>
If the call returns no members, the group is tagged as empty and added to the report.
Each empty group is captured with:
The report is displayed in the console too, for quick visibility.
The report is exported to a CSV file in the system temp folder, Base64-encoded, and emailed to the administrator using Send-MgUserMail.
This gives admins a ready-to-review file without manual exporting.
You can extend this script to provide even stronger governance:
Fetch owners and add a column:
Only report empty groups older than X days (e.g., 30 or 90 days).
Automatically apply a naming prefix like “ToDelete” for review workflows.
Archive empty group reports for yes/no cleanup decisions.
Flag if a group has:
| Error | Cause | Solution |
|---|---|---|
| Insufficient privileges | Missing required Graph permissions. |
Ensure these scopes are present and consented:
|
| Empty results even when empty groups exist | Permission scope not applied correctly, or Graph throttling. | Reconnect with scopes and retry. |
| Send-MgUserMail fails | Admin UPN isn’t a mailbox-enabled account. | Use a licensed mailbox account for $AdminUPN. |
| CSV attachment is blank | No empty M365 groups found. | That’s expected behavior; confirm by checking in Entra Admin Center. |
This script provides a practical and automated way to identify unused Microsoft 365 groups that are not Teams-enabled and have zero members. By emailing the report automatically, it helps administrators keep the tenant clean, audit-friendly, and manageable.
Regularly running this report improves governance, reduces directory clutter, and ensures unused collaboration objects don’t pile up unnoticed.
© m365corner.com. All Rights Reserved. Design by HTML Codex