Private/Get-SIAPagination.ps1

function Get-SIAPagination {
    <#
    Walks a continuation-key-paginated SIA endpoint. Only the Windows strong
    accounts v2 endpoint documents this style, and CyberArk's documentation
    does not pin down the exact JSON property name for the continuation key,
    so a short list of likely names is probed defensively - psSIA stops
    cleanly and returns what it has rather than guessing wrong and looping
    forever or dropping data.
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        $FirstPage,

        [Parameter(Mandatory)]
        [scriptblock]$NextPageRequest,

        [string[]]$ContinuationProperty = @('nextKey', 'NextKey', 'nextPageKey', 'pagingKey', 'continuationToken', 'pageToken'),

        [switch]$NoAutoPaging
    )

    $page = $FirstPage
    $page

    if ($NoAutoPaging) {
        return
    }

    $seenTokens = [System.Collections.Generic.HashSet[string]]::new()
    while ($true) {
        $token = $null
        foreach ($propertyName in $ContinuationProperty) {
            $property = $page.PSObject.Properties[$propertyName]
            if ($property -and $property.Value) {
                $token = [string]$property.Value
                break
            }
        }

        if (-not $token -or -not $seenTokens.Add($token)) {
            break
        }

        $page = & $NextPageRequest $token
        if ($null -eq $page) {
            break
        }
        $page
    }
}