Public/Remove-Account.ps1
|
function Remove-Account { <# .SYNOPSIS Removes an account entry. .DESCRIPTION Deletes an account from the data store by ID. .PARAMETER Id The ID of the account to remove. .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 Remove-Account -Id "abc123" .OUTPUTS None #> [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param( [Parameter(Mandatory, ValueFromPipelineByPropertyName)] [string]$Id, [Parameter()] [string]$Budget, [Parameter()] [string]$DataPath ) process { $resolvedPath = Resolve-DataPath -DataPath $DataPath -Budget $Budget if (-not $resolvedPath) { return } $accounts = Read-EntityData -EntityType 'Account' -DataPath $resolvedPath $account = $accounts | Where-Object { $_.Id -eq $Id } if (-not $account) { Write-Error "Account with ID '$Id' not found." return } if ($PSCmdlet.ShouldProcess($account.Name, "Remove account")) { $updatedAccounts = @($accounts | Where-Object { $_.Id -ne $Id }) if (Write-EntityData -EntityType 'Account' -Data $updatedAccounts -DataPath $resolvedPath) { Write-Verbose "Removed account: $($account.Name)" } } } } |