# LibTmux\Select-TmuxSession

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/SelectTmuxSessionCommand.cs#L8
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-select-tmuxsession/

```
Criteria (default):
Select-TmuxSession
    [-InputObject] <System.Object[]>
    -Criteria <System.Collections.IDictionary>
    [-ExactlyOne]
    [<CommonParameters>]

Query:
Select-TmuxSession
    [-InputObject] <System.Object[]>
    -Query <LibTmux.Query.QueryDocument>
    [-ExactlyOne]
    [<CommonParameters>]
```

[`Filter`](/en/csharp/latest/reference/libtmux-listbuffersrequest-filter/) captured native sessions.

Evaluate criteria against captured native objects using the shared .NET query
evaluator. Selection preserves input order, duplicates, object identity and the
complete graph behind each object. It does not contact tmux or refresh data.
Use [`Where-Object`](https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.4) when an ordinary PowerShell predicate is sufficient.

Ordinary selection streams each match. ExactlyOne retains a match until finite
input completes, then emits it only if exactly one input matched. A second
match, invalid object, unavailable captured relation, evaluation failure or
pipeline stop terminates selection before that retained object is emitted.
ExactlyOne counts only the successful objects it receives. An upstream
nonterminating error is outside that guarantee. When completeness is required
before mutation, use [`-ErrorAction`](/en/powershell/latest/reference/libtmux-select-tmuxsession/#LibTmux%5CSelect-TmuxSession.parameter.ErrorAction) Stop on every upstream acquisition.

### Notes

Errors terminate even with [`-ErrorAction`](/en/powershell/latest/reference/libtmux-select-tmuxsession/#LibTmux%5CSelect-TmuxSession.parameter.ErrorAction) Continue. [`Tmux.NoMatch`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Select-TmuxSession.md#notes) and
[`Tmux.MultipleMatches`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Select-TmuxSession.md#notes) report cardinality failures. [`Tmux.InvalidQuery`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Select-TmuxSession.md#notes) reports
invalid criteria or a mismatched target; [`Tmux.QuerySelectionFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Select-TmuxSession.md#notes) retains
the native evaluation exception and failing input. ExactlyOne cannot prove
cardinality on an input stream that never completes.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Default parameter set:** Criteria
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Session`: Captured native sessions; no property-name binding.
- **Outputs:** `LibTmux.Session`

Related APIs:

- [`New-TmuxQuery`](/en/powershell/latest/reference/libtmux-new-tmuxquery/)
- [`Get-TmuxSnapshot`](/en/powershell/latest/reference/libtmux-get-tmuxsnapshot/)
- [Read captured objects](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/read.md)

## Examples

Example 1

Capture the existing endpoint selected by $SocketPath, then select detached sessions.

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Select-TmuxSession.md).

```powershell
$snapshot = LibTmux\New-TmuxServer -SocketPath $SocketPath |
    LibTmux\Get-TmuxSnapshot
$snapshot.Sessions |
    LibTmux\Select-TmuxSession -Criteria @{ Attached = $false }
```

## Parameters

- `InputObject` (`System.Object[]`): Native LibTmux.Session objects, individually or in an array. The callback validates each object and rejects nulls or lookalike objects.
  Required. Position 0. Accepts pipeline input by value.
- `Criteria` (`System.Collections.IDictionary`): The criteria map copied before input begins. An empty map accepts every valid native input. (for `Criteria`)
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `ExactlyOne` (`System.Management.Automation.SwitchParameter`): Require exactly one match from successfully completed finite input.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Verbose` (`System.Management.Automation.SwitchParameter`): Display verbose messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `vb`.
- `Debug` (`System.Management.Automation.SwitchParameter`): Display debug messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `db`.
- `ErrorAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to non-terminating errors.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ea`.
- `WarningAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to warning messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wa`.
- `InformationAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles information messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `infa`.
- `ProgressAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles progress updates.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `proga`.
- `ErrorVariable` (`System.String`): Store the command's error records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ev`.
- `WarningVariable` (`System.String`): Store the command's warning records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wv`.
- `InformationVariable` (`System.String`): Store the command's information records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `iv`.
- `OutVariable` (`System.String`): Save output in the named variable while passing it down the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ov`.
- `OutBuffer` (`System.Int32`): Buffer output before passing it to the next pipeline command.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ob`.
- `PipelineVariable` (`System.String`): Make the most recent output object available through a named variable within the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `pv`.
- `Query` (`LibTmux.Query.QueryDocument`): A native query document whose target is Session. (for `Query`)
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).

## Returns

`LibTmux.Session`: The original matching objects.
