Searching for guest users in Microsoft Teams

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 | Select GroupId
I get the Group Id for all teams that I am in, listed like so (dummy values):
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 | 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
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!

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 | Get-TeamUser -Role Guest

More on PowerShell pipeline binding: