diff --git a/scripts/aad-get-duplicate-m365group/README.md b/scripts/aad-get-duplicate-m365group/README.md new file mode 100644 index 00000000..af2360b7 --- /dev/null +++ b/scripts/aad-get-duplicate-m365group/README.md @@ -0,0 +1,71 @@ +--- +plugin: add-to-gallery +--- + +# 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. + +# [PnP PowerShell](#tab/pnpps) + +```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 +``` + +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] + +*** + +## Source Credit + +Sample first appeared on [Identifying Duplicate Microsoft 365 Group Names](https://reshmeeauckloo.com/posts/powershell-duplicate-m365group-teams/) + +## Contributors + +| Author(s) | +|-----------| +| [Reshmee Auckloo](https://github.com/reshmee011) | + +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] + diff --git a/scripts/aad-get-duplicate-m365group/assets/preview.png b/scripts/aad-get-duplicate-m365group/assets/preview.png new file mode 100644 index 00000000..792aa4fd Binary files /dev/null and b/scripts/aad-get-duplicate-m365group/assets/preview.png differ diff --git a/scripts/aad-get-duplicate-m365group/assets/sample.json b/scripts/aad-get-duplicate-m365group/assets/sample.json new file mode 100644 index 00000000..bc1e4ab2 --- /dev/null +++ b/scripts/aad-get-duplicate-m365group/assets/sample.json @@ -0,0 +1,57 @@ +[ + { + "name": "aad-get-duplicate-m365group", + "source": "pnp", + "title": "Identifying Duplicate Microsoft 365 Group Names", + "shortDescription": "Identifying duplicate M365 Group to ensure each group has a unique name can help to reduce confusion for end users.", + "url": "https://pnp.github.io/script-samples/aad-get-duplicate-m365group/README.html", + "longDescription": [ + "Identifying duplicate M365 Group to ensure each group has a unique name can help to reduce confusion for end users." + ], + "creationDateTime": "2024-12-07", + "updateDateTime": "2024-12-07", + "products": [ + "M365 Group" + ], + "metadata": [ + { + "key": "PNP-POWERSHELL", + "value": "2.99.63" + } + ], + "categories": [ + "Report", + "Security", + "Governance", + "Microsoft 365 Group" + ], + "tags": [ + "modern", + "Connect-PnPOnline", + "get-PnPMicrosoft365Group" + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/aad-get-duplicate-m365group/assets/preview.png", + "alt": "" + } + ], + "authors": [ + { + "gitHubAccount": "reshmee011", + "company": "", + "pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4", + "name": "Reshmee Auckloo" + } + ], + "references": [ + { + "name": "Want to learn more about PnP PowerShell and the cmdlets", + "description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", + "url": "https://aka.ms/pnp/powershell" + } + ] + } +]