Identifying Duplicate Microsoft 365 Group Names
Summary
It is possible to create M365 Groups and Teams with the same name, and there is currently no built-in way to prevent this. Having duplicate names can cause confusion and increase security, governance and compliance risks.
Prerequisites
- PnP PowerShell https://pnp.github.io/powershell/
- The user account that runs the script must have Global Admin administrator access or Entra ID Admin role.
param (
[Parameter(Mandatory = $true)]
[string] $domain
)
Clear-Host
$dateTime = (Get-Date).toString("dd-MM-yyyy-hh-ss")
$invocation = (Get-Variable MyInvocation).Value
$directorypath = (Split-Path $invocation.MyCommand.Path) + "\"
$exportFilePath = Join-Path -Path $directorypath -ChildPath $([string]::Concat($domain,"-duplicateM365_",$dateTime,".csv"));
$adminSiteURL = "https://$domain-Admin.SharePoint.com"
Connect-PnPOnline -Url $adminSiteURL
# Retrieve all M365 groups
$groups = get-PnPMicrosoft365Group
# Find duplicate group names
$duplicateGroups = $groups | Group-Object DisplayName | Where-Object { $_.Count -gt 1 }
# Create a report
$report = @()
foreach ($group in $duplicateGroups) {
foreach ($item in $group.Group) {
$report += [PSCustomObject]@{
DisplayName = $item.DisplayName
GroupId = $item.Id
Mail = $item.Mail
}
}
}
# Export the report to a CSV file
$report | Export-Csv -Path $exportFilePath -NoTypeInformation
Disconnect-PnPOnline
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Source Credit
Sample first appeared on Identifying Duplicate Microsoft 365 Group Names
Contributors
Author(s) |
---|
Reshmee Auckloo |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.