Report / Security / Configure

Identifying Duplicate Microsoft 365 Group Names

Identifying duplicate M365 Group to ensure each group has a unique name can help to reduce confusion for end users.

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

powershell
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

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.

Tool documentation & references

Keep exploring