diff --git a/scripts/teams-list-ownerless-teams/README.md b/scripts/teams-list-ownerless-teams/README.md new file mode 100644 index 00000000..73079060 --- /dev/null +++ b/scripts/teams-list-ownerless-teams/README.md @@ -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)] + \ No newline at end of file diff --git a/scripts/teams-list-ownerless-teams/assets/preview.png b/scripts/teams-list-ownerless-teams/assets/preview.png new file mode 100644 index 00000000..0081836f Binary files /dev/null and b/scripts/teams-list-ownerless-teams/assets/preview.png differ diff --git a/scripts/teams-list-ownerless-teams/assets/sample.json b/scripts/teams-list-ownerless-teams/assets/sample.json new file mode 100644 index 00000000..c8fa196f --- /dev/null +++ b/scripts/teams-list-ownerless-teams/assets/sample.json @@ -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" + } + ] + } +]