Public/Get-LprMatchListEntry.ps1

function Get-LprMatchListEntry {
    <#
    .SYNOPSIS
        Gets an entry from a named LPR Match List including all custom fields if available
    .DESCRIPTION
        Gets an entry from a named LPR Match List including all custom fields if available
    .EXAMPLE
        PS C:\> Get-LprMatchList -Name Staff -RegistrationNumber ABC123
        Gets the LPR Match List entry matching registration number ABC123, as well as all custom fields and values if available.
    #>

    [CmdletBinding()]
    [OutputType([pscustomobject])]
    param(
        # Specifies the name of the LPR Match List
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Name,

        # Specifies the registration number matching the entry or entries to get.
        # Default is '*' and will return all rows.
        [Parameter()]
        [string]
        $RegistrationNumber = '*'
    )

    begin {
        $ms = Get-ManagementServer
        if ($null -eq $ms.LprMatchListFolder) {
            throw "Milestone XProtect LPR Plugin is not installed or was not loaded in the current session. Please ensure the plugin is installed. If LPR cannot be managed from Management Client on this system, it cannot be managed from PowerShell either."
        }
    }

    process {
        $list = $ms.LprMatchListFolder.LprMatchLists | Where-Object Name -eq $Name
        if ($null -eq $list) {
            Write-Error "No LPR Match List found matching name '$Name'" -Category ObjectNotFound
            return
        }
        $resultFound = $false

        foreach ($entry in $list.MethodIdGetRegistrationNumbersInfoWithResult().RegistrationNumbersWithCustomFields) {
            if ($entry[0] -notlike $RegistrationNumber) {
                continue
            }
            $resultFound = $true
            $row = [ordered]@{ RegistrationNumber = $entry[0] }
            for ($i = 1; $i -lt $entry.Count; $i += 1) {
                $row.Add($list.CustomFields[($i - 1)], $entry[$i])
            }

            Write-Output ([pscustomobject]$row)
        }

        if (-not $resultFound -and $RegistrationNumber -ne '*') {
            Write-Error "No LPR Match List Entry found matching filter `"RegistrationNumber -like '$RegistrationNumber'`"" -Category ObjectNotFound
        }
    }
}