Get list of guests/external users for a Teams

Modified on Wed, 10 Aug 2022 at 08:46 AM

If you are looking for a list of all guest and external users for a specific Teams Group in PowerShell you can use the following function:


param ([string]$Id)
$TeamsGuests = @{}
$OrgName = “@” + (Get-OrganizationConfig).Identity
$Team = (Get-UnifiedGroup -Identity $Id) #Populate the array with current group membership
Get-UnifiedGroupLinks -LinkType Member -Identity $Team.Alias | % { $User = $_.Name.tostring()  #Handle guest users
    if ($User -like "*#EXT#*") {
        $GuestUPN = $User + $OrgName
        $GuestUser = Get-AzureADUser -ObjectId $GuestUPN -ErrorAction SilentlyContinue   #Handle specific case for user displaynames containing commas
        $GuestDisplayName = $GuestUser.DisplayName -replace ",", ""
        $TeamsGuests.Add($GuestDisplayName, $GuestUser.Mail)
    }
}
$TeamsGuestsjson = ($TeamsGuests | ConvertTo-Json)
$TeamsGuestsjsonClean = $TeamsGuestsjson -replace ",", "<br>"
$TeamsGuestsjsonOut = $TeamsGuestsjsonClean.Trim([char]0x007B, [char]0x007D)
return $TeamsGuestsjsonOut


If you want to use this within CoreView as a Custom Action, you can import following script:


{
   "id": "48bb0938-af1d-42db-8cda-c5c7fc69526e",
   "title": "Get Teams Guests",
   "lastModified": "2022-02-09T12:06:34.3330000Z",
   "target": "Teams",
   "tags": [],
   "vars": [],
   "params": [
      {
         "name": "DisplayName",
         "type": "string",
         "isDefault": true
      },
      {
         "name": "Id",
         "type": "string",
         "isDefault": false
      }
   ],
   "columns": {
      "Id": "",
      "DisplayName": ""
   },
   "version": 5,
   "statement": "param ([string]$DisplayName, [string]$Id)\r\n\r\n$TeamsGuests = @{}\n$OrgName = “@”+ (Get-OrganizationConfig).Identity\n$Team = (Get-UnifiedGroup -Identity $Id)\n# Populate the array with current group membership\nGet-UnifiedGroupLinks -LinkType Member -Identity $Team.Alias | % {\n   $User = $_.Name.tostring()\n   # Handle guest users\n   if ($User -like \"*#EXT#*\") {\n      $GuestUPN = $User+$OrgName\n      $GuestUser = Get-AzureADUser -ObjectId $GuestUPN -ErrorAction SilentlyContinue\n      #Handle specific case for user displaynames containing commas\n      $GuestDisplayName = $GuestUser.DisplayName -replace \",\",\"\"\n      $TeamsGuests.Add($GuestDisplayName, $GuestUser.Mail)\n      }\n}\n\n$TeamsGuestsjson = ($TeamsGuests | ConvertTo-Json) \n$TeamsGuestsjsonClean = $TeamsGuestsjson -replace \",\",\"<br>\" -replace \"\"\"\",\"\"\n\n$TeamsGuestsjsonOut = $TeamsGuestsjsonClean.Trim([char]0x007B, [char]0x007D)\n\nreturn $TeamsGuestsjsonOut"
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article