Public/Export-Account.ps1
|
function Export-Account { <# .SYNOPSIS Exports accounts to a file. .DESCRIPTION Exports one or all accounts 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 account name to export. If omitted, exports all accounts. .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-Account -OutputPath "accounts.csv" Exports all accounts to a CSV file. .EXAMPLE Export-Account -Name "Chase Checking" -OutputPath "chase.json" -Format JSON Exports a specific account to JSON format. .EXAMPLE Export-Account -OutputPath "C:\Backups\accounts.csv" -Budget "MyFamilyBudget" Exports all accounts from a specific budget to CSV. .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 accounts $getParams = @{} if ($Name) { $getParams['Name'] = $Name } if ($Budget) { $getParams['Budget'] = $Budget } if ($DataPath) { $getParams['DataPath'] = $DataPath } $accounts = Get-Account @getParams # Build export parameters $exportParams = @{ Data = $accounts OutputPath = $OutputPath Properties = @('Id', 'Name', 'Bank', 'Last4Digits') EntityType = 'account' } if ($Format) { $exportParams['Format'] = $Format } # Use helper for export return Export-EntityData @exportParams } |