Private/Storage/FlatFile/Remove-PukFlatFileRecord.ps1

function Remove-PukFlatFileRecord {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [Parameter(Mandatory)]
        [string]$Path,

        [Parameter(Mandatory)]
        [System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate,

        [Parameter(Mandatory)]
        [string]$DistinguishedName
    )

    $store = Get-PukFlatFileStore -Path $Path -Certificate $Certificate
    $existing = @($store.records) | Where-Object { $_.DistinguishedName -eq $DistinguishedName }

    if (-not $existing) {
        throw "No record found for '$DistinguishedName' in '$Path'."
    }

    if (-not $PSCmdlet.ShouldProcess($DistinguishedName, 'Remove PWSHPUKMGT flat-file record')) {
        return
    }

    $store.records = @(@($store.records) | Where-Object { $_.DistinguishedName -ne $DistinguishedName })
    Set-PukFlatFileStore -Path $Path -Certificate $Certificate -Store $store
}