Public/Teams.ps1
|
<# .SYNOPSIS Finds Microsoft Teams that have no owners. .DESCRIPTION This function finds all Microsoft Teams in the tenant and reports on any that have no owners. .EXAMPLE Get-O365OrphanedTeam .NOTES You must be connected to the Microsoft Graph with the 'Group.Read.All' and 'User.Read.All' scopes before running this function. #> function Get-O365OrphanedTeam { [CmdletBinding()] param() Write-Verbose "Finding orphaned Teams..." # A Team is a Group that is "resourceProvisioningOptions" -eq "Team" $Teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -All $OrphanedTeams = [System.Collections.Generic.List[Object]]::new() foreach ($Team in $Teams) { $Owners = Get-MgGroupOwner -GroupId $Team.Id if ($Owners.Count -eq 0) { $OrphanedTeams.Add($Team) } } Write-Verbose "Found $($OrphanedTeams.Count) orphaned Teams." return $OrphanedTeams } |