Query all MS Teams and Export list of guests added to each Team site

# Connecting to Teams
Connect-MicrosoftTeams

# Connecting to Azure AD
Connect-AzureAD

#Get list of all Teams
$AllTeams = get-team

# For each team extract members
foreach ($team in $AllTeams)
{
  $groupmembers = Get-AzureADGroupMember -ObjectId $team.groupid
  foreach ($member in $groupmembers)
  {
    $array=[ordered]@{
     	"Group ID"=$team.groupid;
     	"Group Name"=$team.DisplayName;
     	"Guest Name"=$member.DisplayName;
     	"Email Address"=$member.mail;
	"Type"=$member.UserType;
  }
  If ( $member.UserType -eq 'Guest')  {
    $obj=New-Object -TypeName psobject -Property $array
    Export-Csv -path "c:\temp\TeamsGuests.csv" -InputObject $obj -Append -NoTypeInformation
  }
}
}
Share
Ryan Wilson
Azure and Office 365 Technical Architect | Microsoft Certified Solutions Associate: Office 365 | Microsoft Certified: Azure Solutions Architect Expert | Microsoft Certified Solutions Expert: Productivity | Microsoft 365 Certified: Enterprise Administrator Expert | Microsoft 365 Certified: Messaging Administrator Associate

Leave a Reply

Your email address will not be published. Required fields are marked *