Searching for guest users in Microsoft Teams

Welcome Forums General PowerShell Q&A Searching for guest users in Microsoft Teams

Viewing 1 reply thread
  • Author
    Posts
    • #200687
      Participant
      Topics: 1
      Replies: 0
      Points: 11
      Rank: Member

      Hi everyone,

      I am trying to figure out how to use PowerShell to search for the guest users I have inside my Microsoft Teams. When I run the following:

      Get-Team -User [email protected] | Select GroupId
      I get the Group Id for all teams that I am in, listed like so (dummy values):
      61e72e0d-eb48-4eq9-b02a-6a29420e9d4f
      9q4b769l-16bb-4040-a740-4208ce9a61f9
      aca41337-fc87-4fdb-9a2d-b14276a514c6
      Next, I can run:
      Get-TeamUser -GroupId 61e72e0d-eb48-4eq9-b02a-6a29420e9d4f -Role Guest
      to see all the guests within an individual group. When I run the following:
      Get-Team -User [email protected] | Select GroupId | Get-TeamUser -GroupId $_ -Role Guest
      I get the error:
      Cannot bind argument to parameter ‘GroupId’ because it is null.
      I also tried
      Get-Team -User [email protected]
      ForEach-Object {
          $_ | Get-TeamUser
      }
      and get the error:
      Get-TeamUser : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the
      parameters that take pipeline input.
      Any suggestions? Thank you very much!
    • #200717
      Senior Moderator
      Topics: 9
      Replies: 1236
      Points: 4,443
      Helping Hand
      Rank: Community Hero

      You have to really understand how the pipelining works. $_ has value only inside a scriptblock when used with some specific cmdlets like Where-Object, Foreach-Object etc and in some other special scenarios, it doesn’t hold a value otherwise.

      From the below doc, I can see that parameter GroupId of Get-TeamUser cmdlet takes input via pipeline, hence you just need to

      Get-Team -User [email protected] | Get-TeamUser -Role Guest
      

      Get-TeamUser: https://docs.microsoft.com/en-us/powershell/module/teams/get-teamuser?view=teams-ps
      More on PowerShell pipeline binding: https://4sysops.com/archives/understanding-powershell-pipeline-parameter-binding/

Viewing 1 reply thread
  • The topic ‘Searching for guest users in Microsoft Teams’ is closed to new replies.