How to get Microsoft Teams guest users

HASSAN BIN NASIR DAR 391 Reputation points
2023-02-02T00:32:26.7833333+00:00

Hi

I want to get a list of guest users who have access on microsoft teams. guest users

Please look snapshot. How to get these guest users by powershell. thanks

Microsoft Teams | Development
Microsoft Security | Microsoft Entra | Microsoft Entra External ID
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Teams | Microsoft Teams for business | Other
{count} votes

4 answers

Sort by: Most helpful
  1. JOSE IGNACIO HERRERA RUIZ 166 Reputation points
    2023-02-02T07:19:32.75+00:00

    Hi,

    The PowerShell cmdlet ‘Get-AzureADUser’ is used to retrieve guest users in the tenant. To list all the guest accounts, run the following. 

    Get-AzureADUser -All $true -Filter "UserType -eq 'Guest'"


  2. JOSE IGNACIO HERRERA RUIZ 166 Reputation points
    2023-02-02T07:23:29.1066667+00:00

    List all guests in Microsoft Teams teams in the tenant and export the results in a CSV.

    Install-Module MicrosoftTeams
    Connect-MicrosoftTeams
    $teams = @()
    $externalteams = @()
    $teams = get-team
    foreach ($team in $teams){
      $groupid = ($team.groupid)
      $users = (Get-TeamUser -GroupId $team.groupid | Where-Object {$_.Role -eq "Guest"})
      $extcount = ($users.count)
      foreach ($extuser in $users){
        $id = $team.groupid
        $teamext = ((Get-Team | Where-Object {$_.groupid -eq "$id"}).DisplayName).ToString()
        $ext = $extuser.User
        $externalteams += [pscustomobject]@{
          ExtUser   = $ext
          GroupID   = $id
          TeamName  = $teamext
    	} 
      }
    }
     if ($externalteams.Count -gt 0){
        Write-Host "Exporting the guest members in teams results.."
        $externalteams | Export-Csv -Path "GuestUsersFromTeams.csv" -NoTypeInformation
        Write-Host "Completed."
     }
     else{
        Write-host "there are no external user added to any team in your organization" -ForegroundColor yellow
     }
    

  3. SokiGuo-MSFT 31,526 Reputation points Microsoft External Staff
    2023-02-02T07:52:10.2333333+00:00

    Hi @Anonymous

    Teams tag is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your problem is related to development, which we are not very familiar. The following suggestion is just for your reference. Thanks for your understanding!

    Please run the following command. Returns an array containing the UPN, UserId, Name and Role of users belonging to a specific GroupId.

    Get-TeamUser -GroupId  -Role Guest
    

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



  4. SokiGuo-MSFT 31,526 Reputation points Microsoft External Staff
    2023-02-03T09:03:05.48+00:00

    Hi @Anonymous

    As he provided the script above, you can easily export all guest users. The following is the complete code, please refer to it.

    Install-Module azuread
    connect-Azuread
    Get-AzureADUser -Filter "UserType eq 'Guest'" | select DisplayName, Mail | Export-Csv guests.csv -NoTypeInformation
    
    Import-Csv -path .\guests.csv
    

    User's image


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.