# LibTmux\Invoke-TmuxControlCommand

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/06233d3c99b40a5bce966c9e1d358f346ff4de55/src/LibTmux.PowerShell/InvokeTmuxControlCommandCommand.cs#L7
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-invoke-tmuxcontrolcommand/

```
Invoke-TmuxControlCommand
    [-Connection] <LibTmux.IControlModeSession>
    [-Command] <LibTmux.TmuxCommand>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Run a native command on a borrowed control client.

Send one native command and emit its reply lines as strings. [`Commands`](/en/csharp/latest/reference/libtmux-tmuxchain-commands/) with
no reply emit no success object. Native commands retain their generation and
placement guards; raw commands use tmux target resolution.

Concurrent callers receive their correlated replies from the core. Cancelling
stops this caller waiting, not a command already sent, and does not dispose
the borrowed client. A later send remains usable after the cancelled command
finishes. [`WhatIf`](/en/powershell/latest/reference/libtmux-invoke-tmuxcontrolcommand/#LibTmux%5CInvoke-TmuxControlCommand.parameter.WhatIf) sends nothing; an empty connection pipeline performs no work.

Literal commands that an optional feature cannot run safely on the daemon's
tmux release are refused before the requested command is dispatched. A command that
needs another release raises LibTmux.TmuxVersionTooLowException. A session
or window name that exactly tmux 3.7 rejects raises
LibTmux.TmuxUnsupportedOnReleaseException, the type that
TmuxVersionTooLowException derives from, so one catch of it covers every
refusal.
Only the command given is checked. A refused command carried inside another
command's text is not: an [if-shell](/en/tmux/latest/manual/if-shell/) or [run-shell](/en/tmux/latest/manual/run-shell/) -C string, [bind-key](/en/tmux/latest/manual/bind-key/),
[set-hook](/en/tmux/latest/manual/set-hook/), [confirm-before](/en/tmux/latest/manual/confirm-before/), a menu, a prompt or choose template, or a brace
block. Nested, it reaches tmux unchanged. A nameless [break-pane](/en/tmux/latest/manual/break-pane/) ends a tmux
3.7 server, so on exactly 3.7 name every [break-pane](/en/tmux/latest/manual/break-pane/), including the one
prefix ! runs, or upgrade to 3.7a. The other failures are listed at
https://libtmux.org/en/powershell/latest/guides/compatibility/#what-the-checks-do-not-read

### Notes

[`Tmux.InvalidCommand`](https://github.com/libtmux/libtmux-powershell/blob/fa5e60c48b312eb0d957d02aad9edcfc50cff359/docs/reference/LibTmux/Invoke-TmuxControlCommand.md#notes) rejects a global option in the command-name position
before dispatch. [`Tmux.ControlCommandFailed`](https://github.com/libtmux/libtmux-powershell/blob/fa5e60c48b312eb0d957d02aad9edcfc50cff359/docs/reference/LibTmux/Invoke-TmuxControlCommand.md#notes) retains native exceptions and the
connection target. [`ErrorAction`](/en/powershell/latest/reference/libtmux-invoke-tmuxcontrolcommand/#LibTmux%5CInvoke-TmuxControlCommand.parameter.ErrorAction) Continue permits later clients to run. The
core bounds pending requests and replies; rejected admission does not retry.
Confirmation identifies the supplied connection without inventing endpoint
metadata absent from [`IControlModeSession`](/en/csharp/latest/reference/libtmux-icontrolmodesession/).

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.IControlModeSession`: The borrowed client to send through.
- **Outputs:** `System.String`

Related APIs:

- [Commands and control clients](https://github.com/libtmux/libtmux-powershell/blob/fa5e60c48b312eb0d957d02aad9edcfc50cff359/docs/commands.md)
- [Tmux release requirements](https://github.com/libtmux/libtmux-powershell/blob/fa5e60c48b312eb0d957d02aad9edcfc50cff359/docs/compatibility.md)

## Examples

Example 1

Print the attached session name using an existing $control owned by your surrounding try/finally scope.

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

```powershell
$command = LibTmux\New-TmuxCommand -Name 'display-message' -Arguments @(
    '-p', '#{session_name}'
)
$control | LibTmux\Invoke-TmuxControlCommand -Command $command
```

## Parameters

- `Connection` (`LibTmux.IControlModeSession`): The native control client. This operation borrows the supplied client.
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Command` (`LibTmux.TmuxCommand`): The native command. Raw commands contain no captured entity identity guard.
  Required. Position 1. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?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`.
- `WhatIf` (`System.Management.Automation.SwitchParameter`): Show the operation without contacting tmux.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Ask for confirmation before the operation.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.

## Returns

`System.String`: Native reply lines, in reply order.

## Guides

Pages that discuss `Invoke-TmuxControlCommand`.

### Guides

- [Commands and control clients](/en/powershell/latest/guides/commands/)
- [Compatibility](/en/powershell/latest/guides/compatibility/)
- [Getting started](/en/powershell/latest/guides/getting-started/)

### Topics

- [Dispatch, completion, and failure](/en/powershell/latest/topics/execution/)
