Public/Remove-LprMatchList.ps1

function Remove-LprMatchList {
    <#
    .SYNOPSIS
        Removes the LPR Match List with the specified name
    .DESCRIPTION
        Removes / Deletes the LPR Match List with the specified name. This is a permanent and irreversible action and
        as such, the ConfirmImpact level is set to High.
    .EXAMPLE
        PS C:\> Remove-LprMatchList -Name Staff
        Permanently deletes the LPR Match List named Staff
    .EXAMPLE
        PS C:\> Remove-LprMatchList -Name Staff -WhatIf
        Shows what would happen if you called Remove-LprMatchList but does not make any changes
    .EXAMPLE
        PS C:\> Remove-LprMatchList -Name Staff -Confirm:$false
        Permanently deletes the LPR Match List named Staff, and bypasses the confirmation dialog.
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')]
    param(
        # Specifies the name of the LPR Match List
        [Parameter(Mandatory, ValueFromPipelineByPropertyName)]
        [ValidateNotNullOrEmpty()]
        [string]
        $Name
    )

    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 {
        $invokeInfo = $ms.LprMatchListFolder.MethodIdRemoveLprMatchList()
        $listId = $invokeInfo.IdValues.$Name
        if ($null -eq $listId) {
            Write-Error "No LPR Match List found matching name '$Name'" -Category ObjectNotFound
            return
        }
        if ($Name -eq 'Unlisted license plate') {
            Write-Error "You are not allowed to remove the default 'Unlisted license plates' LPR match list"
            return
        }

        if ($PSCmdlet.ShouldProcess("LPR Match List '$Name'", "Delete")) {
            $invokeInfo.Id = $listId
            $invokeResult = $invokeInfo.ExecuteDefault()
            if ($invokeResult.State -ne 'Success') {
                Write-Error -Message $invokeResult.ErrorText -ErrorId $invokeResult.ErrorCode -Category ProtocolError
            }
        }
    }
}