curt.psm1

<#
.SYNOPSIS
Interactive certificate picker using certutil + gawk + fzf.

.DESCRIPTION
Wraps certutil -store through gawk for parsing and fzf for multi-select.
Outputs serial numbers or full info of selected certificates.

.EXAMPLE
# Browse current user My store, output serial numbers
curt

# Output full certificate info
curt my i

# Browse LocalMachine My store (requires admin)
curt lm

# Delete selected certs
curt | ForEach-Object { certutil -delstore My $_ }

# Delete from machine store
curt lm | ForEach-Object { certutil -delstore -enterprise My $_ }
#>

function Invoke-Curt {
    [CmdletBinding()]
    [Alias('curt')]
    param(
        [Parameter(Position = 0)]
        [ValidateSet('My', 'Lm')]
        [string]$Store = 'My',

        [Parameter(Position = 1)]
        [ValidateSet('i', 'sno')]
        [string]$Output = 'sno'
    )

    $certutilArgs = if ($Store -eq 'Lm') { @('-store', '-enterprise', 'My') } else { @('-store', 'My') }

    $selected = certutil @certutilArgs |
        gawk 'BEGIN { RS="={10,}"; FPAT="[^:^\n]+:[^\n]+"; OFS="\t" } NF>1 { $1=$1; print }' |
        fzf -m |
        gawk '{ gsub("\t", "\n", $0); print }'

    if (-not $selected) { return }

    if ($Output -eq 'sno') {
        $selected | gawk 'BEGIN { FPAT="Serial Number:[^\n]+"; } NF>0 { gsub("Serial Number: ","", $1); print }'
    } else {
        $selected
    }
}

Export-ModuleMember -Function Invoke-Curt -Alias curt