Private/ConvertTo-LprMatchListEntryList.ps1

function ConvertTo-LprMatchListEntryList {
    [CmdletBinding()]
    [OutputType([System.Collections.Generic.List[LprMatchListEntry]])]
    param (
        # Specifies a row, or rows of pscustomobjects typically retrieved using Get-LprMatchListEntry
        [Parameter(Mandatory, ValueFromPipeline)]
        [pscustomobject[]]
        $InputObject
    )

    process {
        $columns = $InputObject | Get-Member -MemberType NoteProperty | Select-Object -ExpandProperty Name
        $entries = New-Object System.Collections.Generic.List[LprMatchListEntry]
        foreach ($row in $InputObject) {
            $newEntryParams = @{
                RegistrationNumber = $null
                CustomFields = @{}
            }
            foreach ($column in $columns) {
                if ($column -eq 'RegistrationNumber') {
                    $newEntryParams.$column = $row.$column
                }
                else {
                    $newEntryParams.CustomFields.$column = $row.$Column
                }
            }
            if ([string]::IsNullOrWhiteSpace($newEntryParams.RegistrationNumber)) {
                Write-Warning "Missing registrationnumber column in list named $($destination.Name)"
                continue
            }
            $entry = New-LprMatchListEntry @newEntryParams
            $entries.Add($entry)
        }

        Write-Output $entries
    }
}