Public/Get-GCUsers.ps1

<#
.SYNOPSIS
    Retrieves a list of users from Genesys Cloud.

.DESCRIPTION
    Queries the Genesys Cloud API to retrieve a paginated list of users.
    Supports filtering by state, name, specific user IDs, and expanding related resources.
    API Endpoint: GET /api/v2/users

.PARAMETER PageSize
    The number of results per page. Default is 25. Maximum is 500.

.PARAMETER PageNumber
    The page number to retrieve. Default is 1.

.PARAMETER SortOrder
    The sort order for results. Valid values are 'ascending' or 'descending'.

.PARAMETER State
    Filter users by state. Valid values include 'active', 'inactive', 'deleted'.

.PARAMETER Name
    Filter users by name. Supports partial matching.

.PARAMETER Id
    An array of user IDs to retrieve. Allows fetching specific users by their IDs.

.PARAMETER Expand
    An array of fields to expand in the response. Valid values include 'routingStatus',
    'presence', 'integrationPresence', 'conversationSummary', 'outOfOffice', 'geolocation',
    'station', 'authorization', 'lasttokenissued', 'dateLastLogin', 'team', 'profileSkills',
    'certifications', 'locations', 'groups', 'skills', 'languages', 'languagePreference'.

.EXAMPLE
    Get-GCUsers
    Retrieves the first page of users with default page size.

.EXAMPLE
    Get-GCUsers -PageSize 50 -PageNumber 2 -State 'active'
    Retrieves the second page of active users with 50 results per page.

.EXAMPLE
    Get-GCUsers -Name 'John' -Expand @('presence', 'routingStatus')
    Searches for users named John and expands presence and routing status information.

.EXAMPLE
    Get-GCUsers -Id @('user-id-1', 'user-id-2')
    Retrieves specific users by their IDs.

.NOTES
    Genesys Cloud API: GET /api/v2/users
#>

function Get-GCUsers {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $false)]
        [int]$PageSize = 25,

        [Parameter(Mandatory = $false)]
        [int]$PageNumber = 1,

        [Parameter(Mandatory = $false)]
        [string]$SortOrder,

        [Parameter(Mandatory = $false)]
        [string]$State,

        [Parameter(Mandatory = $false)]
        [string]$Name,

        [Parameter(Mandatory = $false)]
        [string[]]$Id,

        [Parameter(Mandatory = $false)]
        [string[]]$Expand
    )

    $queryParams = @{
        pageSize   = $PageSize
        pageNumber = $PageNumber
    }

    if ($SortOrder) { $queryParams['sortOrder'] = $SortOrder }
    if ($State) { $queryParams['state'] = $State }
    if ($Name) { $queryParams['name'] = $Name }
    if ($Id) { $queryParams['id'] = $Id -join ',' }
    if ($Expand) { $queryParams['expand'] = $Expand -join ',' }

    $endpoint = "users"
    return Invoke-GCApiRequest -Endpoint $endpoint -Method GET -QueryParameters $queryParams
}