Private/Get-SFExternalId.ps1

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

        [Parameter(Mandatory)]
        [hashtable]$ResourceTypeConfiguration
    )

    $resourceType = [string]$ResourceTypeConfiguration.Type
    if (-not [string]::IsNullOrWhiteSpace([string]$ResourceTypeConfiguration.IdField)) {
        $field = [string]$ResourceTypeConfiguration.IdField
        $value = Get-SFNestedValue -InputObject $Resource -Path $field
        return ConvertTo-SFExternalIdPart -Value $value -ResourceType $resourceType -Field $field
    }

    $separator = [string]$ResourceTypeConfiguration.IdSeparator
    $parts = foreach ($fieldDefinition in @($ResourceTypeConfiguration.IdFields)) {
        $field = [string]$fieldDefinition.Field
        $value = Get-SFNestedValue -InputObject $Resource -Path $field
        $part = ConvertTo-SFExternalIdPart `
            -Value $value `
            -Format ([string]$fieldDefinition.Format) `
            -ResourceType $resourceType `
            -Field $field

        if ($part.Contains($separator)) {
            throw "External ID field '$field' on resource type '$resourceType' contains the configured separator '$separator'."
        }
        $part
    }

    return $parts -join $separator
}