Skip to content

Commit

Permalink
Merge pull request #789 from reshmee011/dupm365
Browse files Browse the repository at this point in the history
new sample script to identify duplicate m365 group
  • Loading branch information
pkbullock authored Dec 11, 2024
2 parents 933aa65 + ea7e899 commit cd01edf
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 0 deletions.
71 changes: 71 additions & 0 deletions scripts/aad-get-duplicate-m365group/README.md
Original file line number Diff line number Diff line change
@@ -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)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/aad-get-duplicate-m365group" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions scripts/aad-get-duplicate-m365group/assets/sample.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]

0 comments on commit cd01edf

Please sign in to comment.