public/Get-DuoGroup.ps1

<#
.Synopsis
   Retrieve DUO Groups
.DESCRIPTION
   Returns a list of groups.
.EXAMPLE
    Get-DuoGroup
.EXAMPLE
    Get-DuoGroup -username JoeUser
.INPUTS

.OUTPUTS
   [PSCustomObject]DuoRequest
.NOTES
    DUO API
        Method GET
        Path /admin/v1/groups
    PARAMETERS
        None
    RESPONSE CODES
        Response Meaning
        200 Success. Returns a list of users.
.COMPONENT
   The component this cmdlet belongs to
.FUNCTIONALITY
   The functionality that best describes this cmdlet
#>

function Get-DuoGroup() {
    [CmdletBinding(
    )]
    param
    (
        [parameter(Mandatory = $false)]
        [String]$user_id
    )
    [string]$method = "GET"
    [string]$path = "/admin/v1/groups"
    if($user_id){
        [string]$path = "/admin/v1/users/$user_id/groups"
    }

    $outputs = [System.Collections.Generic.List[pscustomobject]]::new()

    $offsets = [system.collections.generic.list[string]]::new()
    $offsets.add('0')
    $offsets.add('100')
    $offsets.add('200')
    $offsets.add('300')
    $offsets.add('400')
    $offsets.add('500')

    foreach($offset in $offsets){
        $apiparams = [system.collections.generic.dictionary[string, string]]::new()
        $apiparams.add('offset', $offset)

        $DuoRequest = Convertto-DUORequest -DuoMethodPath $path -Method $method -ApiParams $ApiParams
        $Response = Invoke-RestMethod @DuoRequest -SkipHeaderValidation:$true
        If ($Response.stat -ne 'OK') {
            Write-Warning 'DUO REST Call Failed'
            Write-Warning ($APiParams | Out-String)
            Write-Warning "Method:$method Path:$path"
        }
        $outputs.add($response.response)

    } # end of foreach
    $outputs = $outputs.getenumerator().foreach({$_})
    write-output -InputObject $outputs

}