Skip to content

Commit

Permalink
Merge pull request #755 from Tanddant/main
Browse files Browse the repository at this point in the history
🔨 - Added teams-list-ownerless-teams sample
  • Loading branch information
pkbullock authored Oct 13, 2024
2 parents a537b47 + 512e4fc commit 1f52377
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 0 deletions.
46 changes: 46 additions & 0 deletions scripts/teams-list-ownerless-teams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
plugin: add-to-gallery
---

# List Ownerless Teams

## Summary

If your organization has been using Microsoft Teams for more that a few years, you'll no doubt have a number of Teams that have been orphaned, probably because the original owner has moved on. This script will list all Teams that have fewer than a specified number of owners, and export them to a CSV file.

# [PnP PowerShell](#tab/pnpps)

```powershell
Connect-PnPOnline -ClientId "GUID" -Tenant "GUID" -CertificatePath -CertificatePassword "Password"
$MinimumRequiredOwners = 1;
$Groups = Get-PnPMicrosoft365Group -IncludeOwners | Where-Object {$_.Owners.Count -le $MinimumRequiredOwners -and $_.HasTeam}
$MappedObjects = [System.Collections.ArrayList]@()
foreach ($Group in $Groups) {
$MappedObject = [PSCustomObject]@{
GroupId = $Group.GroupId
DisplayName = $Group.DisplayName
OwnersCount = $Group.Owners.Count
Owners = $Group.Owners | Select-Object -Property "Email" | Join-String -Property "Email" -Separator "; "
}
$MappedObjects += $MappedObject
}
$fileName = "$(Get-Date -Format ("yyyy-MM-dd"))-GroupsWithFewerThan$($MinimumRequiredOwners)Owners.csv";
$MappedObjects | Select-Object -Property * | Export-Csv -Path ".\$fileName" -Encoding UTF8 -Delimiter ";" -Force;
```

## Contributors

| Author(s) |
|-----------|
| [Dan Toft](https://Dan-Toft.dk) |


[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/teams-list-ownerless-teams" 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/teams-list-ownerless-teams/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"name": "teams-list-ownerless-teams",
"source": "pnp",
"title": "List ownerless teams",
"shortDescription": "Easily identify ownerless teams in your tenant",
"url": "https://pnp.github.io/script-samples/teams-list-ownerless-teams/README.html",
"longDescription": [
"Once an employee leaves, and their account is disabled, the ownership of the Microsoft 365 Group (and the associated Microsoft Teams team) is lost. This script helps you to identify all the teams that have no owner, so you can take the necessary actions to assign a new owner to the team."
],
"creationDateTime": "2024-10-10",
"updateDateTime": "2024-10-10",
"products": [
"Teams"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.2.51"
},
{
"key": "POWERSHELL",
"value": "7.4.5"
}
],
"categories": [
"Report"
],
"tags": [
"Connect-PnPOnline",
"Get-PnPMicrosoft365Group"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/teams-list-ownerless-teams/assets/preview.png",
"alt": "List ownerless teams"
}
],
"authors": [
{
"gitHubAccount": "Tanddant",
"company": "Evobis ApS",
"pictureUrl": "https://github.com/tanddant.png",
"name": "Dan Toft"
}
],
"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 1f52377

Please sign in to comment.