Public/Get-SlackGroup.ps1

function Get-RyverGroup {
    <#
    .SYNOPSIS
        Get information about Ryver groups
 
    .DESCRIPTION
        Get information about Ryver groups
 
    .PARAMETER Token
        Specify a token for authorization.
 
        See 'Authentication' section here for more information: https://api.ryver.com/web
        Test tokens are a simple way to use this
 
    .PARAMETER Name
        One or more group names to return. Defaults to all. Accepts wildcards.
 
    .PARAMETER ExcludeArchived
        Whether to exclude archived groups. Default is to include all.
 
    .PARAMETER Raw
        If specified, we provide raw output and do not parse any responses
 
    .FUNCTIONALITY
        Ryver
    #>

    [CmdletBinding(
        HelpUri = 'https://tlindsay42.github.io/PSRyver/Public/Get-RyverGroup/'
    )]
    param (
        $Token = $Script:PSRyver.Token,
        [String[]]$Name,
        [Switch]$ExcludeArchived,
        [Switch]$Raw
    )
    end {
        Write-Verbose "$($PSBoundParameters | Remove-SensitiveData | Out-String)"

        if ($ExcludeArchived) {
            $body = @{ exclude_archived = 1 }
        }
        else {
            $body = @{ exclude_archived = 0 }
        }
        $params = @{
            Body   = $body
            Token  = $Token
            Method = 'groups.list'
        }
        $RawGroups = Invoke-RyverRestMethod @params

        $HasWildCard = $false
        foreach ($Item in $Name) {
            if ($Item -match '\*') {
                $HasWildCard = $true
                break
            }
        }

        if ($Name -and -not $HasWildCard) {
            # torn between independent queries, or filtering groups.list
            # submit a PR if this isn't performant enough or doesn't make sense.
            $Groups = $RawGroups.groups |
                Where-Object {$Name -Contains $_.name}
        }
        elseif ($Name -and $HasWildCard) {
            $AllGroups = $RawGroups.groups

            # allow like operator on each group requested in the param, avoid dupes
            $GroupHash = [ordered]@{}
            foreach ($RyverGroup in $AllGroups) {
                foreach ($Chan in $Name) {
                    if ($RyverGroup.Name -like $Chan -and -not $GroupHash.Contains($RyverGroup.id)) {
                        $GroupHash.Add($RyverGroup.Id, $RyverGroup)
                    }
                }
            }
            $Groups = $GroupHash.Values
        }
        else { # nothing specified
            $Groups = $RawGroups.groups
        }

        if ($Raw) {
            $RawGroups
        }
        else {
            Format-RyverV1GroupObject -InputObject $Groups
        }
    }
}