# LibTmux\Connect-TmuxControl

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/ConnectTmuxControlCommand.cs#L7
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-connect-tmuxcontrol/

```
Connect-TmuxControl
    [-Server] <LibTmux.Server>
    [-Target] <System.String>
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Attach a native control client to an explicit tmux target.

Attach one control client and return its native [`IControlModeSession`](/en/csharp/latest/reference/libtmux-icontrolmodesession/). The
caller owns the returned client and must dispose it or use
[`Disconnect-TmuxControl`](/en/powershell/latest/reference/libtmux-disconnect-tmuxcontrol/) in finally. The server and its sessions are borrowed.

Target is raw tmux target syntax, resolved when connecting. A name, index or
ID does not carry a captured entity identity guard. No implicit current
session is selected. [`WhatIf`](/en/powershell/latest/reference/libtmux-connect-tmuxcontrol/#LibTmux%5CConnect-TmuxControl.parameter.WhatIf) does not attach a client. An empty server pipeline
performs no work.

### Notes

[`Tmux.ControlConnectFailed`](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Connect-TmuxControl.md#notes) retains the original failure and server target. If
pipeline output fails before the client transfers to the caller, the cmdlet
disposes it. Stop cancels attachment; it never kills the borrowed tmux server.

## 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.Server`: The native endpoint to attach to.
- **Outputs:** `LibTmux.IControlModeSession`

Related APIs:

- [Commands and control clients](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/commands.md)

## Examples

Example 1

Attach to fixture on a previously selected $server. Retain the returned
client and close it in finally with Disconnect-TmuxControl; the task guide
shows a complete ownership scope.

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

```powershell
$server | LibTmux\Connect-TmuxControl -Target 'fixture'
```

## Parameters

- `Server` (`LibTmux.Server`): The explicit endpoint that receives the operation.
  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` (`System.String`): Nonempty raw tmux target to attach to. NUL and whitespace-only values are rejected.
  Required. Position 1. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0). [`ValidatePattern("\\A[^\\x00]*[^\\s\\x00][^\\x00]*\\z")`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatepatternattribute?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

`LibTmux.IControlModeSession`: The newly attached client. Its ownership transfers to the caller.
