When rolling out classifications on Teams in an existing environment it can be good to know how many Teams that already have Guest Users invited. To gather this information I put together an easy PowerShell script. Running this script requires that you install the Microsoft Teams PowerShell module.
#Array for Teams with Guests
$teamswithguests = @()
#Collect all Teams in tenant
$teams = get-team
#Loop to get all Teams with Guests accounts
foreach ($team in $teams){
#Get groupid
$groupid = $team.groupid
#search through teams with guest users
$users = Get-TeamUser -GroupId $groupid |where role -eq "Guest"
$count = $users.count
if ($count -eq "0"){
Write-host "there are no external user added $($team.DisplayName)" -ForegroundColor Cyan
}
else{
$teamswithguests += $team
Write-Host "Team $($team.DisplayName) has these external members" -ForegroundColor DarkMagenta
}
}
#List teams with Guest users
$teamswithguests
Hope this will help you in your Teams rollout.
Regards @jlindoe