Private/Get-SFGroupKey.ps1

function Get-SFGroupKey {
    [CmdletBinding()]
    [OutputType([string])]
    param (
        [Parameter(Mandatory)] $Resource,
        [Parameter(Mandatory)] [string[]]$Fields
    )

    $parts = foreach ($field in $Fields) {
        $value = Get-SFNestedValue -InputObject $Resource -Path $field
        if ($null -eq $value -or ($value -is [string] -and [string]::IsNullOrWhiteSpace($value))) {
            throw "LatestByGroup group field '$field' has no value."
        }
        if ($value -is [System.Collections.IEnumerable] -and $value -isnot [string]) {
            throw "LatestByGroup group field '$field' must contain a scalar value."
        }

        $text = [string]$value
        "$($text.Length):$text"
    }

    return $parts -join '|'
}