Private/Format-RyverV1UserGroupObject.ps1

function Format-RyverV1UserGroupObject {
    <#
    .SYNOPSIS
        Parse user group objects.
 
    .DESCRIPTION
        Parse user group objects.
 
    .INPUTS
        System.Management.Automation.PSCustomObject[]
 
    .INPUTS
        System.Management.Automation.PSCustomObject
 
    .NOTES
        - Troy Lindsay
        - Twitter: @troylindsay42
        - GitHub: tlindsay42
 
    .EXAMPLE
 
    .LINK
        https://tlindsay42.github.io/PSRyver/Private/Format-RyverV1UserGroupObject/
 
    .LINK
        https://github.com/tlindsay42/PSRyver/blob/master/PSRyver/Private/Format-RyverV1UserGroupObject.ps1
 
    .FUNCTIONALITY
        Ryver
    #>

    [CmdletBinding(
        HelpUri = 'https://tlindsay42.github.io/PSRyver/Private/Format-RyverV1UserGroupObject/'
    )]
    [OutputType( [PSCustomObject[]] )]
    [OutputType( [PSCustomObject] )]
    param (
        [Parameter(
            Mandatory = $true,
            Position = 0,
            ValueFromPipeline = $true
        )]
        [PSObject]
        $InputObject
    )

    begin {
        $function = $MyInvocation.MyCommand.Name

        Write-Verbose -Message (
            "Beginning: '${function}' with ParameterSetName '$( $PSCmdlet.ParameterSetName )' and Parameters: " +
            ( $PSBoundParameters | Remove-SensitiveData | Format-Table -AutoSize | Out-String )
        )
    }

    process {
        foreach ( $group in $InputObject ) {
            $users = $null

            if ( $group.Users.Count -gt 0 ) {
                $users = Get-RyverUserFromID -ID $group.Users
                $userCount = $users.Count
            }
            else {
                $userCount = $null
            }

            [PSCustomObject] @{
                PSTypeName  = 'PSRyver.UserGroup'
                ID          = $group.ID
                Name        = $group.Name
                Handle      = $group.Handle
                Description = $group.Description
                Created     = ConvertFrom-UnixTime -UnixTime $group.'Date_Create'
                Updated     = ConvertFrom-UnixTime -UnixTime $group.'Date_Update'
                CreatedBy   = Get-RyverUserFromID -ID $group.'Created_By'
                UpdatedBy   = Get-RyverUserFromID -ID $group.'Updated_By'
                Users       = $users
                UserCount   = $userCount
                Raw         = $group
            }
        }
    }

    end {
        Write-Verbose -Message "Ending: '${function}'."
    }
}