Public/Export-Biller.ps1

function Export-Biller {
    <#
    .SYNOPSIS
        Exports billers to a file.
 
    .DESCRIPTION
        Exports one or all billers from a budget to CSV or JSON format.
 
    .PARAMETER OutputPath
        The file path for the export. Extension determines format (.csv or .json).
 
    .PARAMETER Name
        Optional biller name to export. If omitted, exports all billers.
 
    .PARAMETER Format
        Output format: CSV or JSON. If not specified, determined by file extension.
 
    .PARAMETER Budget
        Optional budget name to target. Uses active budget if not specified.
 
    .PARAMETER DataPath
        Optional custom path for data storage. Overrides budget-based paths.
 
    .EXAMPLE
        Export-Biller -OutputPath "billers.csv"
 
        Exports all billers to a CSV file.
 
    .EXAMPLE
        Export-Biller -Name "Netflix" -OutputPath "netflix.json"
 
        Exports a specific biller to JSON format.
 
    .EXAMPLE
        Export-Biller -OutputPath "C:\Backups\billers.json" -Format JSON -Budget "MyFamilyBudget"
 
        Exports all billers from a specific budget to JSON.
 
    .OUTPUTS
        File path of the exported data
    #>

    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$OutputPath,

        [Parameter()]
        [string]$Name,

        [Parameter()]
        [ValidateSet('CSV', 'JSON')]
        [string]$Format,

        [Parameter()]
        [string]$Budget,

        [Parameter()]
        [string]$DataPath
    )

    # Get billers
    $getParams = @{}
    if ($Name) { $getParams['Name'] = $Name }
    if ($Budget) { $getParams['Budget'] = $Budget }
    if ($DataPath) { $getParams['DataPath'] = $DataPath }

    $billers = Get-Biller @getParams

    # Build export parameters
    $exportParams = @{
        Data = $billers
        OutputPath = $OutputPath
        Properties = @('Id', 'Name', 'StartDate', 'Frequency', 'Amount', 'AccountId')
        EntityType = 'biller'
    }
    if ($Format) { $exportParams['Format'] = $Format }

    # Use helper for export
    return Export-EntityData @exportParams
}