# LibTmux\Invoke-TmuxQuery

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

```
NativeFilter:
Invoke-TmuxQuery
    [-Server] <LibTmux.Server>
    -Target <LibTmux.Query.QueryTarget>
    -NativeFilter <System.String>
    [<CommonParameters>]

Plan:
Invoke-TmuxQuery
    [-Server] <LibTmux.Server>
    -Plan <System.Object>
    [-AsResult]
    [<CommonParameters>]

Query (default):
Invoke-TmuxQuery
    [-Server] <LibTmux.Server>
    -Query <LibTmux.Query.QueryDocument>
    [-Pushdown <LibTmux.Query.QueryPushdown>]
    [-AsResult]
    [<CommonParameters>]
```

Acquire fresh tmux objects using an explicit query.

Inspect the supplied endpoint, acquire a fresh snapshot and emit matching native
objects in captured order. A query document is planned against the observed
daemon version. A prepared plan must match that version. Execution never starts
an absent daemon.

Use AsResult to retain one native [`QueryResult`](/en/csharp/latest/reference/libtmux-query-queryresult/), including its complete snapshot
when there are no matches. Filtering does not prune parent or child relations.
Acquisition spans tmux commands and does not promise an atomic observation.
Use [`Select-TmuxPane`](/en/powershell/latest/reference/libtmux-select-tmuxpane/), [`Select-TmuxWindow`](/en/powershell/latest/reference/libtmux-select-tmuxwindow/) or [`Select-TmuxSession`](/en/powershell/latest/reference/libtmux-select-tmuxsession/) for local filtering
of objects already acquired.

[`NativeFilter`](/en/csharp/latest/reference/libtmux-choosetreerequest-nativefilter/) is a separate raw tmux-format escape hatch. It returns matching
rows without a complete structured-query snapshot. It cannot be combined with
Query, [`Plan`](/en/csharp/latest/reference/libtmux-query-queryextensions-plan/), [`Pushdown`](/en/csharp/latest/reference/libtmux-query-queryplan-pushdown/) or AsResult.

### Notes

Execution failures write [`Tmux.QueryExecutionFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Invoke-TmuxQuery.md#notes) for the affected endpoint. Use [`ErrorAction`](/en/powershell/latest/reference/libtmux-invoke-tmuxquery/#LibTmux%5CInvoke-TmuxQuery.parameter.ErrorAction) Stop to terminate the pipeline. Cancellation stops the pending native operation. No matches are emitted from a failed acquisition.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Default parameter set:** Query
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Server`: An explicit server endpoint.
- **Outputs:** `LibTmux.Session`, `LibTmux.Window`, `LibTmux.Pane`, `LibTmux.Query.QueryResult[LibTmux.Session]`, `LibTmux.Query.QueryResult[LibTmux.Window]`, `LibTmux.Query.QueryResult[LibTmux.Pane]`

Related APIs:

- [`Get-TmuxQueryPlan`](/en/powershell/latest/reference/libtmux-get-tmuxqueryplan/)
- [`New-TmuxQuery`](/en/powershell/latest/reference/libtmux-new-tmuxquery/)
- [`Select-TmuxPane`](/en/powershell/latest/reference/libtmux-select-tmuxpane/)

## Examples

Example 1

Acquire panes at least 80 columns wide from an explicit socket.

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

```powershell
$query = LibTmux\New-TmuxQuery -Target Pane -Criteria @{ Width = @{ Ge = 80 } }
LibTmux\New-TmuxServer -SocketPath $SocketPath |
    LibTmux\Invoke-TmuxQuery -Query $query
```

Example 2

Keep the query result and its captured graph, including an empty selection.

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

```powershell
$query = LibTmux\New-TmuxQuery -Target Pane -Criteria @{ Width = @{ Ge = 80 } }
LibTmux\New-TmuxServer -SocketPath $SocketPath |
    LibTmux\Invoke-TmuxQuery -Query $query -AsResult
```

## Parameters

- `Server` (`LibTmux.Server`): The explicit endpoint to inspect and query.
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Target` (`LibTmux.Query.QueryTarget`): The native entity searched by NativeFilter. (for `NativeFilter`)
  Required. Named parameter. Does not accept pipeline input. [`ValidateSet(["Session","Window","Pane"])`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatesetattribute?view=powershellsdk-7.4.0).
- `NativeFilter` (`System.String`): Uninterpreted tmux format text. The caller owns its semantics; it is not a structured portable query. (for `NativeFilter`)
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0).
- `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`.
- `Plan` (`System.Object`): A native QueryPlan<Session>, QueryPlan<Window> or QueryPlan<Pane> prepared by Get-TmuxQueryPlan or the .NET API. (for `Plan`)
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `AsResult` (`System.Management.Automation.SwitchParameter`): Emit one native result with matches and its complete captured graph. (for `Plan`; `Query`)
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Documented default: `False`.
- `Query` (`LibTmux.Query.QueryDocument`): A native document planned using the observed daemon version. (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).
- `Pushdown` (`LibTmux.Query.QueryPushdown`): Auto permits exact source evaluation and local residuals; Never evaluates locally; Require rejects residual predicates. (for `Query`)
  Optional. Named parameter. Does not accept pipeline input. Documented default: `Auto`. [`ValidateSet(["Auto","Never","Require"])`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatesetattribute?view=powershellsdk-7.4.0).

## Returns

`LibTmux.Session`: Matching sessions.

`LibTmux.Window`: Matching window placements.

`LibTmux.Pane`: Matching panes in their captured placement context.

`LibTmux.Query.QueryResult<T>`: One native result when AsResult is set.
