Public/Get-Account.ps1
|
function Get-Account { <# .SYNOPSIS Retrieves account entries. .DESCRIPTION Gets one or more accounts from the data store. Can filter by name or ID. .PARAMETER Name Filter accounts by name. .PARAMETER Id Get a specific account by ID. .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 Get-Account .EXAMPLE Get-Account -Name "Checking" .OUTPUTS Array of Account objects #> [CmdletBinding(DefaultParameterSetName = 'All')] param( [Parameter(ParameterSetName = 'ByName')] [string]$Name, [Parameter(ParameterSetName = 'ById')] [string]$Id, [Parameter()] [string]$Budget, [Parameter()] [string]$DataPath ) $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget if (-not $resolvedPath) { return @() } $accounts = Read-EntityData -EntityType 'Account' -DataPath $resolvedPath if ($PSCmdlet.ParameterSetName -eq 'ByName') { $accounts = $accounts | Where-Object { $_.Name -like "*$Name*" } } elseif ($PSCmdlet.ParameterSetName -eq 'ById') { $accounts = $accounts | Where-Object { $_.Id -eq $Id } } return $accounts } |