Functions/Teams/Get-JoinedTeams.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Function Get-JoinedTeams
{
    [CmdletBinding()]
    Param(
        [Parameter(Mandatory = $true, ParameterSetName = "users/{id}/joinedTeams",
                   ValueFromPipelineByPropertyName = $true)]
        [ValidateNotNullOrEmpty()]
        [string[]]$UserId
    )

    # if ($global:PowerGraph_AccessToken.TokenType -eq "Client Credentials")
    # { Write-Warning "You cannot currently retrieve Plans for a Group using the Client Credentials authorization model. You might need to call Connect-MSGraph with a username and password first instead." }

    switch ($PsCmdlet.ParameterSetName)
    {
        "users/{id}/joinedTeams" {

            #Todo: Validate UserId is valid for type

            if ($global:PowerGraph_AccessToken.TokenType -eq "Password")
                { Write-Warning "This operation is not support for this type of login ('Delegated') to the API. Please try using 'Connect-MSGraph' without a username and password." }

            $uri = $global:PowerGraph_BaseUrl + "users/$UserId/joinedTeams"
        }

        default {
            if ($global:PowerGraph_AccessToken.TokenType -eq "Client Credentials")
                { Write-Warning "This operation is not support for this type of login ('Application') to the API. Please try using 'Connect-MSGraph' with a username and password." }

            $uri = $global:PowerGraph_BaseUrl + "me/joinedTeams"
        }
    }
    
    $return = Invoke-MSGraphRequest -Uri $uri

    return $return.value

}

#reference: https://docs.microsoft.com/en-gb/graph/api/user-list-joinedteams?view=graph-rest-1.0&tabs=http