Public/Export-LprMatchList.ps1

function Export-LprMatchList {
    <#
    .SYNOPSIS
        Exports the named LPR Match List(s) in a portable JSON format which can be imported again using Import-LprMatchList
    .DESCRIPTION
        Exports one or more LPR Match Lists including all configurable properties. By default, all LPR Match Lists will be
        selected, and you may specify one or more lists using a name with or without a wildcard character.
    .EXAMPLE
        PS C:\> Export-LprMatchList -Path .\lprlists.json
        Exports all LPR Match Lists to the file lprlists.json in the current directory.
    #>

    [CmdletBinding()]
    param (
        # Specifies the name of the LPR Match List
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]
        $Name = '*',

        # Specifies the full path to the json file where the LPR Match List(s) should be exported
        [Parameter(Mandatory)]
        [string]
        $Path
    )

    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 {
        $rows = New-Object system.collections.generic.list[pscustomobject]
        foreach ($list in $ms.LprMatchListFolder.LprMatchLists | Where-Object Name -like $Name) {
            $row = [ordered]@{
                Id = $list.Id
                Name = $list.Name
                Description = $list.Description
                CustomFields = $list.CustomFields
                TriggerEventList = $list.TriggerEventList
                List = $list | Get-LprMatchListEntry
            }
            $rows.Add($row)
        }
        $rows | ConvertTo-Json -Depth 5 | Set-Content -Path $Path -Encoding UTF8
    }
}