Public/Groups/Get-KB4GroupMember.ps1

<#
.SYNOPSIS
Gets members of a KnowBe4 group.

.DESCRIPTION
Retrieves users who belong to a specific KnowBe4 group. Normal output unwraps
KnowBe4 page data and returns user objects. Use Raw to inspect the full response
envelope and page wrapper.

.PARAMETER GroupId
The KnowBe4 group ID.

.PARAMETER All
Retrieves all available pages.

.PARAMETER PageSize
The number of group members to request per page. Valid range is 1 through 500.

.PARAMETER Page
The page number to request when using page-based pagination.

.PARAMETER Cursor
The cursor value to request. Use 'true' to start cursor pagination manually.

.PARAMETER UsePagePagination
Uses page-based pagination when All is specified. Cursor pagination is preferred.

.PARAMETER Raw
Returns the full PSKB4Reporting response envelope instead of unwrapped member objects.

.EXAMPLE
Get-KB4GroupMember -GroupId 123

Gets the first page of users in group 123.

.EXAMPLE
Get-KB4GroupMember -GroupId 123 -All

Gets all users in group 123.

.OUTPUTS
PSCustomObject.
#>

function Get-KB4GroupMember
{
    [CmdletBinding()]
    param(
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [int] $GroupId,

        [Parameter()]
        [switch] $All,

        [Parameter()]
        [ValidateRange(1, 500)]
        [int] $PageSize = 100,

        [Parameter()]
        [ValidateRange(1, [int]::MaxValue)]
        [int] $Page,

        [Parameter()]
        [string] $Cursor,

        [Parameter()]
        [switch] $UsePagePagination,

        [Parameter()]
        [switch] $Raw
    )

    process
    {
        $path = '/v1/groups/{0}/members' -f (Format-KB4PathValue -Value $GroupId)
        $pagedParameters = @{
            Path              = $path
            All               = $All
            PageSize          = $PageSize
            UsePagePagination = $UsePagePagination
            Raw               = $Raw
        }
        if ($PSBoundParameters.ContainsKey('Page'))
        {
            $pagedParameters['Page'] = $Page
        }
        if ($PSBoundParameters.ContainsKey('Cursor'))
        {
            $pagedParameters['Cursor'] = $Cursor
        }

        Invoke-KB4PagedRequest @pagedParameters
    }
}