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 first.last@company.com | 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 first.last@company.com | 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 first.last@company.com
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 first.last@company.com | Get-TeamUser -Role Guest

Get-TeamUser: Get-TeamUser (MicrosoftTeamsPowerShell) | Microsoft Docs
More on PowerShell pipeline binding: https://4sysops.com/archives/understanding-powershell-pipeline-parameter-binding/