Created
July 30, 2020 16:02
-
-
Save win2000b/2bf14dc731bdf6db6dc2295eede9a67d to your computer and use it in GitHub Desktop.
Query All Microsoft Teams and Export list of guests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment